From 7d67b4d9195346e133b2553df06237a4e4a3a3bf Mon Sep 17 00:00:00 2001 From: Ori Livneh Date: Thu, 25 Feb 2016 20:49:41 -0800 Subject: [PATCH] Prevent duplicate memcached lookups for user record User::loadFromId() will look up the user in the database or in memcached -- but it does not allow for the possibility that the record has already been retrieved. On a typical page request on the Wikimedia cluster, this causes over a dozen duplicate memcached lookups for the user record. Bug: T128157 Change-Id: Iec1504700ab566ca89d0ef868d495238b151034a --- includes/user/User.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/includes/user/User.php b/includes/user/User.php index eb3853a45d..90c05d82c3 100644 --- a/includes/user/User.php +++ b/includes/user/User.php @@ -458,12 +458,18 @@ class User implements IDBAccessObject { } $cache = ObjectCache::getMainWANInstance(); - $data = $cache->get( $this->getCacheKey( $cache ) ); - if ( !is_array( $data ) || $data['mVersion'] < self::VERSION ) { - // Object is expired - return false; - } + $key = $this->getCacheKey( $cache ); + $processCache = ObjectCache::getLocalServerInstance( 'hash' ); + $data = $processCache->get( $key ); + if ( !is_array( $data ) ) { + $data = $cache->get( $key ); + if ( !is_array( $data ) || $data['mVersion'] < self::VERSION ) { + // Object is expired + return false; + } + $processCache->set( $key, $data ); + } wfDebug( "User: got user {$this->mId} from cache\n" ); // Restore from cache -- 2.20.1