Aaron Schulz has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/326191 )

Change subject: Convert isSourcePage() to using WAN cache
......................................................................

Convert isSourcePage() to using WAN cache

This deals with replication/snapshot lag and cache slams
(via preemptive random invalidation).

Change-Id: I07e0f533c2e67a821373ec87f295b7f90564850f
---
M TranslateUtils.php
M tag/TranslatablePage.php
2 files changed, 13 insertions(+), 13 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Translate 
refs/changes/91/326191/1

diff --git a/TranslateUtils.php b/TranslateUtils.php
index c21f505..8fa8751 100644
--- a/TranslateUtils.php
+++ b/TranslateUtils.php
@@ -385,7 +385,7 @@
        /**
         * Get a DB handle suitable for read and read-for-write cases
         *
-        * @return DatabaseBase Master for HTTP POST, CLI, DB already changed; 
slave otherwise
+        * @return IDatabase Master for HTTP POST, CLI, DB already changed; 
slave otherwise
         */
        public static function getSafeReadDB() {
                // Parsing APIs need POST for payloads but are read-only, so 
avoid spamming
diff --git a/tag/TranslatablePage.php b/tag/TranslatablePage.php
index 3b9a5bb..3ca6c07 100644
--- a/tag/TranslatablePage.php
+++ b/tag/TranslatablePage.php
@@ -843,20 +843,20 @@
         * @return bool
         */
        public static function isSourcePage( Title $title ) {
-               static $cache = null;
+               $cache = ObjectCache::getMainWANInstance();
+               $translatablePageIds = $cache->getWithSetCallback(
+                       $cache->makeKey( 'pagetranslation', 'sourcepages' ),
+                       $cache::TTL_MINUTE * 5,
+                       function ( $oldValue, &$ttl, array &$setOpts ) {
+                               $dbr = TranslateUtils::getSafeReadDB();
+                               $setOpts += Database::getCacheSetOptions( $dbr 
);
 
-               $cacheObj = wfGetCache( CACHE_ANYTHING );
-               $cacheKey = wfMemcKey( 'pagetranslation', 'sourcepages' );
+                               return TranslatablePage::getTranslatablePages();
+                       },
+                       [ 'pcTTL' => $cache::TTL_PROC_LONG, 'pcGroup' => 
__CLASS__ . ':30' ]
+               );
 
-               if ( $cache === null ) {
-                       $cache = $cacheObj->get( $cacheKey );
-               }
-               if ( !is_array( $cache ) ) {
-                       $cache = self::getTranslatablePages();
-                       $cacheObj->set( $cacheKey, $cache, 60 * 5 );
-               }
-
-               return in_array( $title->getArticleID(), $cache );
+               return in_array( $title->getArticleID(), $translatablePageIds );
        }
 
        /**

-- 
To view, visit https://gerrit.wikimedia.org/r/326191
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I07e0f533c2e67a821373ec87f295b7f90564850f
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

Reply via email to