Krinkle has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/249327

Change subject: User: Migrate from foreign cache to global cache for 
UserRightsProxy
......................................................................

User: Migrate from foreign cache to global cache for UserRightsProxy

Instead of one wiki accessing another wiki's private key space,
use the global key space to share cache values.

Also, Imitating wfMemcKey from wfForeignMemcKey is semantically
incorrect due to $wgCachePrefix having precedence. But most
interfaces (e.g. UserRightsProxy, FileRepo, JobQueue etc.) only
have access to the wiki id (dbname + prefix). The local cache
configuration is not and should not have to be exposed.

Instead start enforcing that local cache keys are left private and
to share keys, they must be exposed as global keys.

Global keys (prefixed with "global:") have their own space and we
can use the wiki-id as deterministic key segment, regardless any
local $wgCachePrefix configuration.

Change-Id: I58836a24b9e239f460ab489bd2fe8ced8259833c
---
M includes/User.php
M includes/UserRightsProxy.php
M includes/objectcache/ObjectCache.php
3 files changed, 19 insertions(+), 18 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/27/249327/1

diff --git a/includes/User.php b/includes/User.php
index 1727a4a..571e2f6 100644
--- a/includes/User.php
+++ b/includes/User.php
@@ -401,8 +401,9 @@
                        return false;
                }
 
-               $key = wfMemcKey( 'user', 'id', $this->mId );
-               $data = ObjectCache::getMainWANInstance()->get( $key );
+               $cache = ObjectCache::getMainWANInstance();
+               $key = $cache->makeGlobalKey( wfWikiID(), 'user', 'id', 
$this->mId );
+               $data = $cache->get( $key );
                if ( !is_array( $data ) || $data['mVersion'] < self::VERSION ) {
                        // Object is expired
                        return false;
@@ -438,10 +439,11 @@
                        $data[$name] = $this->$name;
                }
                $data['mVersion'] = self::VERSION;
-               $key = wfMemcKey( 'user', 'id', $this->mId );
 
+               $cache = ObjectCache::getMainWANInstance();
+               $key = $cache->makeGlobalKey( wfWikiID(), 'user', 'id', 
$this->mId );
                $opts = Database::getCacheSetOptions( wfGetDB( DB_SLAVE ) );
-               ObjectCache::getMainWANInstance()->set( $key, $data, 3600, 
$opts );
+               $cache->set( $key, $data, 3600, $opts );
        }
 
        /** @name newFrom*() static factory methods */
@@ -2234,12 +2236,13 @@
                        return;
                }
 
-               $key = wfMemcKey( 'user', 'id', $id );
+               $cache = ObjectCache::getMainWANInstance();
+               $key = $cache->makeGlobalKey( wfWikiID(), 'user', 'id', $id );
                if ( $mode === 'refresh' ) {
-                       ObjectCache::getMainWANInstance()->delete( $key, 1 );
+                       $cache->delete( $key, 1 );
                } else {
-                       wfGetDB( DB_MASTER )->onTransactionPreCommitOrIdle( 
function() use ( $key ) {
-                               ObjectCache::getMainWANInstance()->delete( $key 
);
+                       wfGetDB( DB_MASTER )->onTransactionPreCommitOrIdle( 
function() use ( $cache, $key ) {
+                               $cache->delete( $key );
                        } );
                }
        }
diff --git a/includes/UserRightsProxy.php b/includes/UserRightsProxy.php
index 3a3eb53..bb2e7d5 100644
--- a/includes/UserRightsProxy.php
+++ b/includes/UserRightsProxy.php
@@ -278,9 +278,12 @@
                        array( 'user_id' => $this->id ),
                        __METHOD__ );
 
-               $key = wfForeignMemcKey( $this->database, false, 'user', 'id', 
$this->id );
-               $this->db->onTransactionPreCommitOrIdle( function() use ( $key 
) {
-                       ObjectCache::getMainWANInstance()->delete( $key );
+               $that = $this;
+               $this->db->onTransactionPreCommitOrIdle( function() use ( $that 
) {
+                       // See User::saveToCache()
+                       $cache = ObjectCache::getMainWANInstance();
+                       $key = $cache->makeGlobalKey( $that->db->getWikiID(), 
'user', 'id', $that->id );
+                       $cache->delete( $key );
                } );
        }
 }
diff --git a/includes/objectcache/ObjectCache.php 
b/includes/objectcache/ObjectCache.php
index 59c3c1f..c8810ba 100644
--- a/includes/objectcache/ObjectCache.php
+++ b/includes/objectcache/ObjectCache.php
@@ -137,19 +137,14 @@
         * @return string
         */
        public static function getDefaultKeyspace() {
-               global $wgCachePrefix, $wgDBname, $wgDBprefix;
+               global $wgCachePrefix;
 
                $keyspace = $wgCachePrefix;
                if ( is_string( $keyspace ) && $keyspace !== '' ) {
                        return $keyspace;
                }
 
-               $keyspace = $wgDBname;
-               if ( is_string( $wgDBprefix ) && $wgDBprefix !== '' ) {
-                       $keyspace .= '-' . $wgDBprefix;
-               }
-
-               return $keyspace;
+               return wfWikiID();
        }
 
        /**

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I58836a24b9e239f460ab489bd2fe8ced8259833c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Krinkle <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to