diff options
Diffstat (limited to 'MLEB/Translate/specials/SpecialLanguageStats.php')
-rw-r--r-- | MLEB/Translate/specials/SpecialLanguageStats.php | 39 |
1 files changed, 31 insertions, 8 deletions
diff --git a/MLEB/Translate/specials/SpecialLanguageStats.php b/MLEB/Translate/specials/SpecialLanguageStats.php index 3fc58c22..d1b1e2d0 100644 --- a/MLEB/Translate/specials/SpecialLanguageStats.php +++ b/MLEB/Translate/specials/SpecialLanguageStats.php @@ -116,6 +116,7 @@ class SpecialLanguageStats extends SpecialPage { $out = $this->getOutput(); $out->addModules( 'ext.translate.special.languagestats' ); + $out->addModuleStyles( 'ext.translate.statstable' ); $params = explode( '/', $par ); @@ -159,11 +160,29 @@ class SpecialLanguageStats extends SpecialPage { "<div class='error'>$1</div>", 'translate-langstats-incomplete' ); + } - // $this->purge is only true if request was posted + if ( $this->incomplete || $this->purge ) { DeferredUpdates::addCallableUpdate( function () { - $flags = $this->purge ? MessageGroupStats::FLAG_NO_CACHE : 0; - $this->loadStatistics( $this->target, $flags ); + // Attempt to recache on the fly the missing stats, unless a + // purge was requested, because that is likely to time out. + // Even though this is executed inside a deferred update, it + // counts towards the maximum execution time limit. If that is + // reached, or any other failure happens, no updates at all + // will be written into the database, as it does only single + // update at the end. Hence we always add a job too, so that + // even the slower updates will get done at some point. In + // regular case (no purge), the job sees that the stats are + // already updated, so it is not much of an overhead. + $jobParams = $this->getCacheRebuildJobParameters( $this->target ); + $jobParams[ 'purge' ] = $this->purge; + $job = MessageGroupStatsRebuildJob::newJob( $jobParams ); + JobQueueGroup::singleton()->push( $job ); + + // $this->purge is only true if request was posted + if ( !$this->purge ) { + $this->loadStatistics( $this->target ); + } } ); } if ( $this->nothing ) { @@ -176,19 +195,23 @@ class SpecialLanguageStats extends SpecialPage { } /** - * Get stats + * Get stats. * @param string $target For which target to get stats * @param int $flags See MessageGroupStats for possible flags * @return array[] */ - protected function loadStatistics( $target, $flags ) { + protected function loadStatistics( $target, $flags = 0 ) { return MessageGroupStats::forLanguage( $target, $flags ); } + protected function getCacheRebuildJobParameters( $target ) { + return [ 'languagecode' => $target ]; + } + /** - * Return the list of allowed values for target here. + * Return true if language exist in the list of allowed languages or false otherwise. * @param string $value - * @return array + * @return bool */ protected function isValidValue( $value ) { $langs = Language::fetchLanguageNames(); @@ -481,7 +504,7 @@ class SpecialLanguageStats extends SpecialPage { $params[] = md5( $groupId ); $params[] = $this->getLanguage()->getCode(); $params[] = md5( $this->target ); - $cachekey = wfMemcKey( __METHOD__, implode( '-', $params ) ); + $cachekey = wfMemcKey( __METHOD__ . '-v3', implode( '-', $params ) ); $cacheval = wfGetCache( CACHE_ANYTHING )->get( $cachekey ); if ( is_string( $cacheval ) ) { return $cacheval; |