From 5b4bd1632755d973efcaa44a57ca6f2d4156df5a Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Tue, 7 Apr 2015 19:58:40 -0700 Subject: [PATCH] Made User::invalidateCache() use touch() instead of the DB query * 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 | 37 +++++++------------------------------ 1 file changed, 7 insertions(+), 30 deletions(-) diff --git a/includes/User.php b/includes/User.php index f23d7dd9f9..f526fe0de4 100644 --- a/includes/User.php +++ b/includes/User.php @@ -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(); } /** -- 2.20.1