[MediaWiki-commits] [Gerrit] Deferred user_touched update via onTransactionIdle. - change (mediawiki/core)
Tim Starling has submitted this change and it was merged. Change subject: Deferred user_touched update via onTransactionIdle. .. Deferred user_touched update via onTransactionIdle. * This should reduce deadlocks and lock wait timeouts. Change-Id: I7d028f9efbe6b2f73240aa653eb9775020f33e8c --- M includes/User.php 1 file changed, 17 insertions(+), 16 deletions(-) Approvals: Tim Starling: Verified; Looks good to me, approved diff --git a/includes/User.php b/includes/User.php index dc68502..9427a9e 100644 --- a/includes/User.php +++ b/includes/User.php @@ -1969,28 +1969,29 @@ * 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(); } } -- To view, visit https://gerrit.wikimedia.org/r/55931 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I7d028f9efbe6b2f73240aa653eb9775020f33e8c Gerrit-PatchSet: 3 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Aaron Schulz asch...@wikimedia.org Gerrit-Reviewer: Demon ch...@wikimedia.org Gerrit-Reviewer: Tim Starling tstarl...@wikimedia.org Gerrit-Reviewer: jenkins-bot ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] Deferred user_touched update via onTransactionIdle. - change (mediawiki/core)
Aaron Schulz has uploaded a new change for review. https://gerrit.wikimedia.org/r/55931 Change subject: Deferred user_touched update via onTransactionIdle. .. Deferred user_touched update via onTransactionIdle. Change-Id: I7d028f9efbe6b2f73240aa653eb9775020f33e8c --- M includes/User.php 1 file changed, 17 insertions(+), 16 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/31/55931/1 diff --git a/includes/User.php b/includes/User.php index 0e63704..78cf711 100644 --- a/includes/User.php +++ b/includes/User.php @@ -1950,28 +1950,29 @@ * 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(); } } -- To view, visit https://gerrit.wikimedia.org/r/55931 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I7d028f9efbe6b2f73240aa653eb9775020f33e8c Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Aaron Schulz asch...@wikimedia.org ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits