From 7e0d148f5790711f992f96f76a1e78e61d711db9 Mon Sep 17 00:00:00 2001 From: Gilles Dubuc Date: Tue, 16 Aug 2016 13:44:08 +0200 Subject: [PATCH] Move thumbnail rendering to a more appropriate spot At the moment the job might start before the transaction that creates the file's row in the DB has had a chance to run. Bug: T106740 Change-Id: If5b94e83d8bbcc6aebfe7193f7b580f03cbd627d --- includes/filerepo/file/LocalFile.php | 29 ++++++++++++++++++++++++++++ includes/upload/UploadBase.php | 21 -------------------- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/includes/filerepo/file/LocalFile.php b/includes/filerepo/file/LocalFile.php index 6eed22214c..91d628c826 100644 --- a/includes/filerepo/file/LocalFile.php +++ b/includes/filerepo/file/LocalFile.php @@ -973,6 +973,33 @@ class LocalFile extends File { DeferredUpdates::addUpdate( new CdnCacheUpdate( $urls ), DeferredUpdates::PRESEND ); } + /** + * Prerenders a configurable set of thumbnails + * + * @since 1.28 + */ + public function prerenderThumbnails() { + global $wgUploadThumbnailRenderMap; + + $jobs = []; + + $sizes = $wgUploadThumbnailRenderMap; + rsort( $sizes ); + + foreach ( $sizes as $size ) { + if ( $this->isVectorized() || $this->getWidth() > $size ) { + $jobs[] = new ThumbnailRenderJob( + $this->getTitle(), + [ 'transformParams' => [ 'width' => $size ] ] + ); + } + } + + if ( $jobs ) { + JobQueueGroup::singleton()->lazyPush( $jobs ); + } + } + /** * Delete a list of thumbnails visible at urls * @param string $dir Base dir of the files. @@ -1525,6 +1552,8 @@ class LocalFile extends File { # Update backlink pages pointing to this title if created LinksUpdate::queueRecursiveJobsForTable( $this->getTitle(), 'imagelinks' ); } + + $this->prerenderThumbnails(); } ), DeferredUpdates::PRESEND diff --git a/includes/upload/UploadBase.php b/includes/upload/UploadBase.php index 03c864a387..9f534d2eb6 100644 --- a/includes/upload/UploadBase.php +++ b/includes/upload/UploadBase.php @@ -774,27 +774,6 @@ abstract class UploadBase { * @since 1.25 */ public function postProcessUpload() { - global $wgUploadThumbnailRenderMap; - - $jobs = []; - - $sizes = $wgUploadThumbnailRenderMap; - rsort( $sizes ); - - $file = $this->getLocalFile(); - - foreach ( $sizes as $size ) { - if ( $file->isVectorized() || $file->getWidth() > $size ) { - $jobs[] = new ThumbnailRenderJob( - $file->getTitle(), - [ 'transformParams' => [ 'width' => $size ] ] - ); - } - } - - if ( $jobs ) { - JobQueueGroup::singleton()->push( $jobs ); - } } /** -- 2.20.1