diff options
Diffstat (limited to 'MLEB/Translate/tag/TranslationsUpdateJob.php')
-rw-r--r-- | MLEB/Translate/tag/TranslationsUpdateJob.php | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/MLEB/Translate/tag/TranslationsUpdateJob.php b/MLEB/Translate/tag/TranslationsUpdateJob.php index f3020f41..0384b4ed 100644 --- a/MLEB/Translate/tag/TranslationsUpdateJob.php +++ b/MLEB/Translate/tag/TranslationsUpdateJob.php @@ -1,4 +1,6 @@ <?php +use MediaWiki\Extensions\Translate\Jobs\GenericTranslateJob; + /** * Job for updating translation units and translation pages when * a translatable page is marked for translation. @@ -9,7 +11,7 @@ * * @since 2016.03 */ -class TranslationsUpdateJob extends Job { +class TranslationsUpdateJob extends GenericTranslateJob { /** * @inheritDoc */ @@ -39,6 +41,12 @@ class TranslationsUpdateJob extends Job { } public function run() { + // WARNING: Nothing here must not depend on message index being up to date. + // For performance reasons, message index rebuild is run a separate job after + // everything else is updated. + + $this->logInfo( 'Starting TranslationsUpdateJob' ); + $page = TranslatablePage::newFromTitle( $this->title ); $sections = $this->params[ 'sections' ]; foreach ( $sections as $index => $section ) { @@ -56,25 +64,46 @@ class TranslationsUpdateJob extends Job { $job->run(); } + $this->logInfo( + 'Finished running ' . count( $unitJobs ) . ' MessageUpdate jobs for ' + . count( $sections ) . ' sections' + ); + // Ensure we are using the latest group definitions. This is needed so // that in long running scripts we do see the page which was just // marked for translation. Otherwise getMessageGroup in the next line // returns null. There is no need to regenerate the global cache. MessageGroups::singleton()->clearProcessCache(); - // Ensure fresh definitions for MessageIndex and stats + // Ensure fresh definitions for stats $page->getMessageGroup()->clearCaches(); - MessageIndex::singleton()->rebuild(); + $this->logInfo( 'Cleared caches' ); - // Refresh translations statistics + // Refresh translations statistics, we want these to be up to date for the + // RenderJobs, for displaying up to date statistics on the translation pages. $id = $page->getMessageGroupId(); MessageGroupStats::forGroup( $id, MessageGroupStats::FLAG_NO_CACHE ); + $this->logInfo( 'Updated the message group stats' ); + // Try to avoid stale statistics on the base page $wikiPage = WikiPage::factory( $page->getTitle() ); $wikiPage->doPurge(); + $this->logInfo( 'Finished purging' ); + // These can be run independently and in parallel if possible $renderJobs = self::getRenderJobs( $page ); JobQueueGroup::singleton()->push( $renderJobs ); + $this->logInfo( 'Added ' . count( $renderJobs ) . ' RenderJobs to the queue' ); + + // Schedule message index update. Thanks to front caching, it is okay if this takes + // a while (and on large wikis it does take a while!). Running it as a separate job + // also allows de-duplication in case multiple translatable pages are being marked + // for translation in a short period of time. + $job = MessageIndexRebuildJob::newJob(); + JobQueueGroup::singleton()->push( $job ); + + $this->logInfo( 'Finished TranslationsUpdateJob' ); + return true; } |