From: Aaron Schulz Date: Tue, 26 Mar 2013 18:41:52 +0000 (-0700) Subject: Deferred user_touched update via onTransactionIdle. X-Git-Tag: 1.31.0-rc.0~20139 X-Git-Url: http://git.cyclocoop.org/%22.%28%24lien.?a=commitdiff_plain;h=d3281c2b5cf49027fef27a06a29cfe1e1570bfa1;p=lhc%2Fweb%2Fwiklou.git Deferred user_touched update via onTransactionIdle. * This should reduce deadlocks and lock wait timeouts. Change-Id: I7d028f9efbe6b2f73240aa653eb9775020f33e8c --- diff --git a/includes/User.php b/includes/User.php index dc6850263a..9427a9eeac 100644 --- a/includes/User.php +++ b/includes/User.php @@ -1969,28 +1969,29 @@ class User { * for reload on the next hit. */ public function invalidateCache() { - if( wfReadOnly() ) { + if ( wfReadOnly() ) { return; } $this->load(); - if( $this->mId ) { + if ( $this->mId ) { $this->mTouched = self::newTouchedTimestamp(); $dbw = wfGetDB( DB_MASTER ); - - // 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__ - ); - } - + $userid = $this->mId; + $touched = $this->mTouched; + $dbw->onTransactionIdle( function() use ( $dbw, $userid, $touched ) { + // 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(); } }