From dc0fae6f6a98b7b9dcadefed688825165d0ae1d6 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Tue, 16 Apr 2013 12:43:04 -0700 Subject: [PATCH] Reduced DB contention in User::saveOptions(). Change-Id: Ic91501cd6476dae54b54b85f2f06c25bd2577c9b --- includes/User.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/includes/User.php b/includes/User.php index ed97deb2e7..eda8bc9d7d 100644 --- a/includes/User.php +++ b/includes/User.php @@ -4428,8 +4428,18 @@ class User { } $dbw = wfGetDB( DB_MASTER ); - $dbw->delete( 'user_properties', array( 'up_user' => $userId ), __METHOD__ ); - $dbw->insert( 'user_properties', $insert_rows, __METHOD__ ); + $hasRows = $dbw->selectField( 'user_properties', '1', + array( 'up_user' => $userId ), __METHOD__ ); + + if ( $hasRows ) { + // Only do this delete if there is something there. A very large portion of + // calls to this function are for setting 'rememberpassword' for new accounts. + // Doing this delete for new accounts with no rows in the table rougly causes + // gap locks on [max user ID,+infinity) which causes high contention since many + // updates will pile up on each other since they are for higher (newer) user IDs. + $dbw->delete( 'user_properties', array( 'up_user' => $userId ), __METHOD__ ); + } + $dbw->insert( 'user_properties', $insert_rows, __METHOD__, array( 'IGNORE' ) ); } /** -- 2.20.1