From: Aaron Schulz Date: Tue, 16 Apr 2013 19:43:04 +0000 (-0700) Subject: Reduced DB contention in User::saveOptions(). X-Git-Tag: 1.31.0-rc.0~19979^2 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/exercices/journal.php?a=commitdiff_plain;h=dc0fae6f6a98b7b9dcadefed688825165d0ae1d6;p=lhc%2Fweb%2Fwiklou.git Reduced DB contention in User::saveOptions(). Change-Id: Ic91501cd6476dae54b54b85f2f06c25bd2577c9b --- 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' ) ); } /**