Improve Caching in Title::loadRestrictions()
authorAndrew Green <andrew.green.df@gmail.com>
Tue, 19 Mar 2019 22:16:11 +0000 (16:16 -0600)
committerAndrew Green <andrew.green.df@gmail.com>
Tue, 19 Mar 2019 22:16:11 +0000 (16:16 -0600)
Change-Id: I9a7edf6fc7d0bb0f4129fe13323964e9fae791f3

includes/Title.php

index 88a7efb..2e43b8d 100644 (file)
@@ -3342,12 +3342,17 @@ class Title implements LinkTarget, IDBAccessObject {
                                $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
                                $rows = $cache->getWithSetCallback(
                                        // Page protections always leave a new null revision
-                                       $cache->makeKey( 'page-restrictions', $id, $this->getLatestRevID() ),
+                                       $cache->makeKey( 'page-restrictions-v1', $id, $this->getLatestRevID() ),
                                        $cache::TTL_DAY,
                                        function ( $curValue, &$ttl, array &$setOpts ) use ( $loadRestrictionsFromDb ) {
                                                $dbr = wfGetDB( DB_REPLICA );
 
                                                $setOpts += Database::getCacheSetOptions( $dbr );
+                                               $lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
+                                               if ( $lb->hasOrMadeRecentMasterChanges() ) {
+                                                       // @TODO: cleanup Title cache and caller assumption mess in general
+                                                       $ttl = WANObjectCache::TTL_UNCACHEABLE;
+                                               }
 
                                                return $loadRestrictionsFromDb( $dbr );
                                        }