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
This commit is contained in:
parent
8e6154c878
commit
7d67b4d919
1 changed files with 11 additions and 5 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue