From d3281c2b5cf49027fef27a06a29cfe1e1570bfa1 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Tue, 26 Mar 2013 11:41:52 -0700 Subject: [PATCH] Deferred user_touched update via onTransactionIdle. * This should reduce deadlocks and lock wait timeouts. Change-Id: I7d028f9efbe6b2f73240aa653eb9775020f33e8c --- includes/User.php | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) 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(); } } -- 2.20.1