Aaron Schulz has uploaded a new change for review. https://gerrit.wikimedia.org/r/203202
Change subject: Optimized translator list loading ...................................................................... Optimized translator list loading * Re-use cache of other threads when unblocked by them * If the queue depth or timeout limit is hit, use the stale cache if possible Bug: T54728 Change-Id: I2e5db955f0723094f95f0c63d0049ab2354cddfc --- M specials/SpecialSupportedLanguages.php 1 file changed, 48 insertions(+), 18 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Translate refs/changes/02/203202/1 diff --git a/specials/SpecialSupportedLanguages.php b/specials/SpecialSupportedLanguages.php index 13365b0..bd4d832 100644 --- a/specials/SpecialSupportedLanguages.php +++ b/specials/SpecialSupportedLanguages.php @@ -68,17 +68,7 @@ $out->addWikiMsg( 'supportedlanguages-colorlegend', $this->getColorLegend() ); - $work = new PoolCounterWorkViaCallback( - 'TranslateFetchTranslators', - "TranslateFetchTranslators-$code", - array( - 'doWork' => function () use ( $code ) { - return $this->fetchTranslators( $code ); - } - ) - ); - $users = $work->execute(); - + $users = $this->fetchTranslators( $code ); if ( $users === false ) { // generic-pool-error is from MW core $out->wrapWikiMsg( '<div class="warningbox">$1</div>', 'generic-pool-error' ); @@ -185,19 +175,61 @@ return $data; } + /** + * Fetch the translators for a language with caching + * + * @param string $code + * @return array|bool Map of (user name => page count) or false on failure + */ public function fetchTranslators( $code ) { - global $wgTranslateMessageNamespaces; - $cache = wfGetCache( CACHE_ANYTHING ); - $cachekey = wfMemcKey( 'translate-supportedlanguages-translator-list', $code ); + $cachekey = wfMemcKey( 'translate-supportedlanguages-translator-list-v1', $code ); + if ( $this->purge ) { $cache->delete( $cachekey ); + $data = false; } else { + $staleCutoffUnix = time() - 3600; $data = $cache->get( $cachekey ); - if ( is_array( $data ) ) { - return $data; + if ( is_array( $data ) && $data['asOfTime'] > $staleCutoffUnix ) { + return $data['users']; } } + + $that = $this; + $work = new PoolCounterWorkViaCallback( + 'TranslateFetchTranslators', + "TranslateFetchTranslators-$code", + array( + 'doWork' => function () use ( $that, $code, $cache, $cachekey ) { + $users = $that->loadTranslators( $code ); + $newData = array( 'users' => $users, 'asOfTime' => time() ); + $cache->set( $cachekey, $newData, 86400 ); + return $users; + }, + 'doCachedWork' => function () use ( $cache, $cachekey ) { + $newData = $cache->get( $cachekey ); + // Use new cache value from other thread + return is_array( $newData ) ? $newData['users'] : false; + }, + 'fallback' => function () use ( $data ) { + // Use stale cache if possible + return is_array( $data ) ? $data['users'] : false; + } + ) + ); + + return $work->execute(); + } + + /** + * Fetch the translators for a language + * + * @param type $code + * @return array Map of (user name => page count) + */ + public function loadTranslators( $code ) { + global $wgTranslateMessageNamespaces; $dbr = wfGetDB( DB_SLAVE ); $tables = array( 'page', 'revision' ); @@ -218,8 +250,6 @@ foreach ( $res as $row ) { $data[$row->rev_user_text] = $row->count; } - - $cache->set( $cachekey, $data, 3600 ); return $data; } -- To view, visit https://gerrit.wikimedia.org/r/203202 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I2e5db955f0723094f95f0c63d0049ab2354cddfc Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Translate Gerrit-Branch: master Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits