From: Aaron Date: Fri, 11 May 2012 22:18:14 +0000 (-0700) Subject: Reduced contention slam potential in User::invalidateCache(). X-Git-Tag: 1.31.0-rc.0~23609^2 X-Git-Url: http://git.cyclocoop.org/%22.%28%24lien.?a=commitdiff_plain;h=8ffaa46662e3326079d51ba52190fdfee3e7630f;p=lhc%2Fweb%2Fwiklou.git Reduced contention slam potential in User::invalidateCache(). Change-Id: If40f368072d97e244295522003fbaa9c082f8f7c --- diff --git a/includes/User.php b/includes/User.php index cb146b5879..5de4b2c5bb 100644 --- a/includes/User.php +++ b/includes/User.php @@ -1287,7 +1287,7 @@ class User { # Proxy blocking if ( !$block instanceof Block && $ip !== null && !$this->isAllowed( 'proxyunbannable' ) - && !in_array( $ip, $wgProxyWhitelist ) ) + && !in_array( $ip, $wgProxyWhitelist ) ) { # Local list if ( self::isLocallyBlockedProxy( $ip ) ) { @@ -1926,10 +1926,19 @@ class User { $this->mTouched = self::newTouchedTimestamp(); $dbw = wfGetDB( DB_MASTER ); - $dbw->update( 'user', - array( 'user_touched' => $dbw->timestamp( $this->mTouched ) ), - array( 'user_id' => $this->mId ), - __METHOD__ ); + + // Prevent contention slams by checking user_touched first + $now = $dbw->timestamp( $this->mTouched ); + $needsPurge = $dbw->selectField( 'user', '1', + array( 'user_id' => $this->mId, 'user_touched < ' . $dbw->addQuotes( $now ) ) + ); + if ( $needsPurge ) { + $dbw->update( 'user', + array( 'user_touched' => $now ), + array( 'user_id' => $this->mId, 'user_touched < ' . $dbw->addQuotes( $now ) ), + __METHOD__ + ); + } $this->clearSharedCache(); } @@ -3014,7 +3023,7 @@ class User { */ public function getPageRenderingHash() { wfDeprecated( __METHOD__, '1.17' ); - + global $wgUseDynamicDates, $wgRenderHashAppend, $wgLang, $wgContLang; if( $this->mHash ){ return $this->mHash;