From e5d41cca909a8ec1b19c6c080388c885854be3f7 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Wed, 21 Nov 2012 13:58:50 -0800 Subject: [PATCH] [Upload] [Schema] Added us_props column to avoid expensive GETs. * 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 | 1 + includes/installer/MysqlUpdater.php | 1 + includes/installer/SqliteUpdater.php | 1 + includes/upload/UploadFromStash.php | 2 +- includes/upload/UploadStash.php | 11 ++++++++--- maintenance/archives/patch-uploadstash-us_props.sql | 2 ++ maintenance/tables.sql | 6 ++++-- 7 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 maintenance/archives/patch-uploadstash-us_props.sql diff --git a/RELEASE-NOTES-1.21 b/RELEASE-NOTES-1.21 index 73a41b59c8..af7264aba3 100644 --- a/RELEASE-NOTES-1.21 +++ b/RELEASE-NOTES-1.21 @@ -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. diff --git a/includes/installer/MysqlUpdater.php b/includes/installer/MysqlUpdater.php index c00dc13f4c..06ec158732 100644 --- a/includes/installer/MysqlUpdater.php +++ b/includes/installer/MysqlUpdater.php @@ -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' ), ); } diff --git a/includes/installer/SqliteUpdater.php b/includes/installer/SqliteUpdater.php index 472283de2f..1d6bca0a7a 100644 --- a/includes/installer/SqliteUpdater.php +++ b/includes/installer/SqliteUpdater.php @@ -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' ), ); } diff --git a/includes/upload/UploadFromStash.php b/includes/upload/UploadFromStash.php index 607965f3f3..55209d4840 100644 --- a/includes/upload/UploadFromStash.php +++ b/includes/upload/UploadFromStash.php @@ -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 ); diff --git a/includes/upload/UploadStash.php b/includes/upload/UploadStash.php index 09bcaeafd4..e608df23b5 100644 --- a/includes/upload/UploadStash.php +++ b/includes/upload/UploadStash.php @@ -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 index 0000000000..d64515a804 --- /dev/null +++ b/maintenance/archives/patch-uploadstash-us_props.sql @@ -0,0 +1,2 @@ +ALTER TABLE /*$wgDBprefix*/uploadstash + ADD COLUMN us_props blob; diff --git a/maintenance/tables.sql b/maintenance/tables.sql index aae5042418..330514ee5b 100644 --- a/maintenance/tables.sql +++ b/maintenance/tables.sql @@ -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, -- 2.20.1