Made User::invalidateCache() use touch() instead of the DB query
authorAaron Schulz <aschulz@wikimedia.org>
Wed, 8 Apr 2015 02:58:40 +0000 (19:58 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Wed, 8 Apr 2015 02:59:35 +0000 (19:59 -0700)
* This method is used for clearing the User cache as well
  as bumping the value of getTouched() for HTTP 304 logic.
  These do not need to do the actual user_touched update.
* This also avoids problems with setting mTouched but
  deferring the update. That confused the CAS update
  logic since it expects mTouched to be in the DB.

Change-Id: I96b30f5c9c8b4714e6663b187f741954a13312cf

includes/User.php

index f23d7dd..f526fe0 100644 (file)
@@ -2202,6 +2202,8 @@ class User implements IDBAccessObject {
         *   page. Ignored if null or !$val.
         */
        public function setNewtalk( $val, $curRev = null ) {
+               global $wgMemc;
+
                if ( wfReadOnly() ) {
                        return;
                }
@@ -2216,7 +2218,6 @@ class User implements IDBAccessObject {
                        $field = 'user_id';
                        $id = $this->getId();
                }
-               global $wgMemc;
 
                if ( $val ) {
                        $changed = $this->updateNewtalk( $field, $id, $curRev );
@@ -2268,37 +2269,13 @@ class User implements IDBAccessObject {
        }
 
        /**
-        * Immediately touch the user data cache for this account.
-        * Updates user_touched field, and removes account data from memcached
-        * for reload on the next hit.
+        * Immediately touch the user data cache for this account
+        *
+        * Calls touch() and removes account data from memcached
         */
        public function invalidateCache() {
-               if ( wfReadOnly() ) {
-                       return;
-               }
-               $this->load();
-               if ( $this->mId ) {
-                       $this->mTouched = $this->newTouchedTimestamp();
-
-                       $dbw = wfGetDB( DB_MASTER );
-                       $userid = $this->mId;
-                       $touched = $this->mTouched;
-                       $method = __METHOD__;
-                       $dbw->onTransactionIdle( function () use ( $dbw, $userid, $touched, $method ) {
-                               // Prevent contention slams by checking user_touched first
-                               $encTouched = $dbw->addQuotes( $dbw->timestamp( $touched ) );
-                               $needsPurge = $dbw->selectField( 'user', '1',
-                                       array( 'user_id' => $userid, 'user_touched < ' . $encTouched ) );
-                               if ( $needsPurge ) {
-                                       $dbw->update( 'user',
-                                               array( 'user_touched' => $dbw->timestamp( $touched ) ),
-                                               array( 'user_id' => $userid, 'user_touched < ' . $encTouched ),
-                                               $method
-                                       );
-                               }
-                       } );
-                       $this->clearSharedCache();
-               }
+               $this->touch();
+               $this->clearSharedCache();
        }
 
        /**