[Upload] [Schema] Added us_props column to avoid expensive GETs.
authorAaron Schulz <aschulz@wikimedia.org>
Wed, 21 Nov 2012 21:58:50 +0000 (13:58 -0800)
committerAaron Schulz <aschulz@wikimedia.org>
Mon, 3 Dec 2012 18:23:40 +0000 (10:23 -0800)
* We already compute the props when stashing, so including that in a column
  lets us reuse it later when the stashed file is to be published.

Change-Id: I3d6adb6528f1e992d8986058806e745c4e1c0300

RELEASE-NOTES-1.21
includes/installer/MysqlUpdater.php
includes/installer/SqliteUpdater.php
includes/upload/UploadFromStash.php
includes/upload/UploadStash.php
maintenance/archives/patch-uploadstash-us_props.sql [new file with mode: 0644]
maintenance/tables.sql

index 73a41b5..af7264a 100644 (file)
@@ -52,6 +52,7 @@ production.
   preview from the edit page.
 * Added EditPage::showStandardInputs:options hook to allow extensions to add
   new fields to the "editOptions" area of the edit form.
+* Upload stash DB schema altered to improve upload performance.
 
 === Bug fixes in 1.21 ===
 * (bug 40353) SpecialDoubleRedirect should support interwiki redirects.
index c00dc13..06ec158 100644 (file)
@@ -227,6 +227,7 @@ class MysqlUpdater extends DatabaseUpdater {
                        array( 'addField', 'job',           'job_token',         'patch-job_token.sql' ),
                        array( 'addField', 'job',           'job_attempts',       'patch-job_attempts.sql' ),
                        array( 'doEnableProfiling' ),
+                       array( 'addField', 'uploadstash',      'us_props',      'patch-uploadstash-us_props.sql' ),
                );
        }
 
index 472283d..1d6bca0 100644 (file)
@@ -107,6 +107,7 @@ class SqliteUpdater extends DatabaseUpdater {
                        array( 'addField', 'job',           'job_token',         'patch-job_token.sql' ),
                        array( 'addField', 'job',           'job_attempts',      'patch-job_attempts.sql' ),
                        array( 'doEnableProfiling' ),
+                       array( 'addField', 'uploadstash',      'us_props',      'patch-uploadstash-us_props.sql' ),
                );
        }
 
index 607965f..55209d4 100644 (file)
@@ -98,7 +98,7 @@ class UploadFromStash extends UploadBase {
                 */
                $metadata = $this->stash->getMetadata( $key );
                $this->initializePathInfo( $name,
-                       $this->getRealPath ( $metadata['us_path'] ),
+                       $this->getRealPath( $metadata['us_path'] ),
                        $metadata['us_size'],
                        false
                );
index 09bcaea..e608df2 100644 (file)
@@ -106,7 +106,6 @@ class UploadStash {
         * @return UploadStashFile
         */
        public function getFile( $key, $noAuth = false ) {
-
                if ( ! preg_match( self::KEY_FORMAT_REGEX, $key ) ) {
                        throw new UploadStashBadPathException( "key '$key' is not in a proper format" );
                }
@@ -131,8 +130,13 @@ class UploadStash {
                        $this->initFile( $key );
 
                        // fetch fileprops
-                       $path = $this->fileMetadata[$key]['us_path'];
-                       $this->fileProps[$key] = $this->repo->getFileProps( $path );
+                       if ( strlen( $this->fileMetadata[$key]['us_props'] ) ) {
+                               $this->fileProps[$key] = unserialize( $this->fileMetadata[$key]['us_props'] );
+                       } else { // b/c for rows with no us_props
+                               wfDebug( __METHOD__ . " fetched props for $key from file\n" );
+                               $path = $this->fileMetadata[$key]['us_path'];
+                               $this->fileProps[$key] = $this->repo->getFileProps( $path );
+                       }
                }
 
                if ( ! $this->files[$key]->exists() ) {
@@ -257,6 +261,7 @@ class UploadStash {
                        'us_key' => $key,
                        'us_orig_path' => $path,
                        'us_path' => $stashPath, // virtual URL
+                       'us_props' => serialize( $fileProps ),
                        'us_size' => $fileProps['size'],
                        'us_sha1' => $fileProps['sha1'],
                        'us_mime' => $fileProps['mime'],
diff --git a/maintenance/archives/patch-uploadstash-us_props.sql b/maintenance/archives/patch-uploadstash-us_props.sql
new file mode 100644 (file)
index 0000000..d64515a
--- /dev/null
@@ -0,0 +1,2 @@
+ALTER TABLE /*$wgDBprefix*/uploadstash
+  ADD COLUMN us_props blob;
index aae5042..330514e 100644 (file)
@@ -994,8 +994,10 @@ CREATE TABLE /*_*/uploadstash (
   -- chunk counter starts at 0, current offset is stored in us_size
   us_chunk_inx int unsigned NULL,
 
-  -- file properties from File::getPropsFromPath.  these may prove unnecessary.
-  --
+  -- Serialized file properties from File::getPropsFromPath
+  us_props blob,
+
+  -- file size in bytes
   us_size int unsigned NOT NULL,
   -- this hash comes from File::sha1Base36(), and is 31 characters
   us_sha1 varchar(31) NOT NULL,