X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FUser.php;h=75649a788144dbb3d424519ea9f95ea633e47d9f;hb=a3e6a32d014a4dbdab58c4e50d98bec93b671932;hp=f089f087078f0d67bdf838268cc058fed4681660;hpb=c14fcf8015fdfb22e8717f2f7135eea5f2a943d3;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/User.php b/includes/User.php index f089f08707..75649a7881 100644 --- a/includes/User.php +++ b/includes/User.php @@ -385,10 +385,10 @@ class User implements IDBAccessObject { return false; } - // Try cache (unless this needs to lock the DB). + // Try cache (unless this needs data from the master DB). // NOTE: if this thread called saveSettings(), the cache was cleared. - $locking = ( ( $flags & self::READ_LOCKING ) == self::READ_LOCKING ); - if ( $locking || !$this->loadFromCache() ) { + $latest = DBAccessObjectUtils::hasFlags( $flags, self::READ_LATEST ); + if ( $latest || !$this->loadFromCache() ) { wfDebug( "User: cache miss for user {$this->mId}\n" ); // Load from DB (make sure this thread sees its own changes) if ( wfGetLB()->hasOrMadeRecentMasterChanges() ) { @@ -458,7 +458,8 @@ class User implements IDBAccessObject { $data['mVersion'] = self::VERSION; $key = wfMemcKey( 'user', 'id', $this->mId ); - ObjectCache::getMainWANInstance()->set( $key, $data, 3600 ); + $opts = Database::getCacheSetOptions( wfGetDB( DB_SLAVE ) ); + ObjectCache::getMainWANInstance()->set( $key, $data, 3600, $opts ); } /** @name newFrom*() static factory methods */ @@ -934,7 +935,7 @@ class User implements IDBAccessObject { * the cached User object, we assume that whatever mechanism is setting * the expiration date is also expiring the User cache. * @since 1.23 - * @return string|bool The datestamp of the expiration, or null if not set + * @return string|null The datestamp of the expiration, or null if not set */ public function getPasswordExpireDate() { $this->load(); @@ -1481,11 +1482,12 @@ class User implements IDBAccessObject { if ( $success ) { $this->mTouched = $newTouched; + $this->clearSharedCache(); + } else { + // Clears on failure too since that is desired if the cache is stale + $this->clearSharedCache( 'refresh' ); } - // Clears on failure too since that is desired if the cache is stale - $this->clearSharedCache(); - return $success; } @@ -2279,22 +2281,29 @@ class User implements IDBAccessObject { } /** - * Clear user data from memcached. - * Use after applying fun updates to the database; caller's + * Clear user data from memcached + * + * Use after applying updates to the database; caller's * responsibility to update user_touched if appropriate. * * Called implicitly from invalidateCache() and saveSettings(). + * + * @param string $mode Use 'refresh' to clear now; otherwise before DB commit */ - public function clearSharedCache() { + public function clearSharedCache( $mode = 'changed' ) { $id = $this->getId(); if ( !$id ) { return; } $key = wfMemcKey( 'user', 'id', $id ); - wfGetDB( DB_MASTER )->onTransactionPreCommitOrIdle( function() use ( $key ) { - ObjectCache::getMainWANInstance()->delete( $key ); - } ); + if ( $mode === 'refresh' ) { + ObjectCache::getMainWANInstance()->delete( $key, 1 ); + } else { + wfGetDB( DB_MASTER )->onTransactionPreCommitOrIdle( function() use ( $key ) { + ObjectCache::getMainWANInstance()->delete( $key ); + } ); + } } /** @@ -3499,7 +3508,7 @@ class User implements IDBAccessObject { $request = $this->getRequest(); } $params['secure'] = $secure; - $request->response()->setcookie( $name, $value, $exp, $params ); + $request->response()->setCookie( $name, $value, $exp, $params ); } /** @@ -3699,7 +3708,7 @@ class User implements IDBAccessObject { if ( !$dbw->affectedRows() ) { // Maybe the problem was a missed cache update; clear it to be safe - $this->clearSharedCache(); + $this->clearSharedCache( 'refresh' ); // User was changed in the meantime or loaded with stale data $from = ( $this->queryFlagsUsed & self::READ_LATEST ) ? 'master' : 'slave'; throw new MWException( @@ -4843,7 +4852,7 @@ class User implements IDBAccessObject { $dbw->update( 'user', array( 'user_editcount=user_editcount+1' ), - array( 'user_id' => $this->getId() ), + array( 'user_id' => $this->getId(), 'user_editcount IS NOT NULL' ), __METHOD__ ); // Lazy initialization check...