Merge "Fixed sanity cache clear in User::saveSettings()"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Mon, 28 Sep 2015 22:21:16 +0000 (22:21 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 28 Sep 2015 22:21:16 +0000 (22:21 +0000)
1  2 
includes/User.php

diff --combined includes/User.php
@@@ -1203,15 -1203,18 +1203,15 @@@ class User implements IDBAccessObject 
                        return false;
                }
  
 -              $db = ( $flags & self::READ_LATEST )
 -                      ? wfGetDB( DB_MASTER )
 -                      : wfGetDB( DB_SLAVE );
 +              list( $index, $options ) = DBAccessObjectUtils::getDBOptions( $flags );
 +              $db = wfGetDB( $index );
  
                $s = $db->selectRow(
                        'user',
                        self::selectFields(),
                        array( 'user_id' => $this->mId ),
                        __METHOD__,
 -                      ( ( $flags & self::READ_LOCKING ) == self::READ_LOCKING )
 -                              ? array( 'LOCK IN SHARE MODE' )
 -                              : array()
 +                      $options
                );
  
                $this->queryFlagsUsed = $flags;
  
                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;
        }
  
        }
  
        /**
-        * 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 );
+                       } );
+               }
        }
  
        /**
  
                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(