From: Aaron Schulz Date: Fri, 17 Apr 2015 20:04:35 +0000 (-0700) Subject: Reduce change for deadlocks in Block::insert() X-Git-Tag: 1.31.0-rc.0~11667^2 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/operations/recherche.php?a=commitdiff_plain;h=89d5f0ef61d8ec22a07cbd521393d2c91356c79f;p=lhc%2Fweb%2Fwiklou.git Reduce change for deadlocks in Block::insert() Bug: T96428 Change-Id: Idb266c8de7b5d7d85339ecc58044c28005527c89 --- diff --git a/includes/Block.php b/includes/Block.php index 0e2188dba2..76667511b8 100644 --- a/includes/Block.php +++ b/includes/Block.php @@ -443,11 +443,15 @@ class Block { $dbw->insert( 'ipblocks', $row, __METHOD__, array( 'IGNORE' ) ); $affected = $dbw->affectedRows(); + $this->mId = $dbw->insertId(); # Don't collide with expired blocks. - # Do this after trying to insert to avoid pointless gap locks. + # Do this after trying to insert to avoid locking. if ( !$affected ) { - $dbw->delete( 'ipblocks', + # T96428: The ipb_address index uses a prefix on a field, so + # use a standard SELECT + DELETE to avoid annoying gap locks. + $ids = $dbw->selectFieldValues( 'ipblocks', + 'ipb_id', array( 'ipb_address' => $row['ipb_address'], 'ipb_user' => $row['ipb_user'], @@ -455,13 +459,14 @@ class Block { ), __METHOD__ ); - - $dbw->insert( 'ipblocks', $row, __METHOD__, array( 'IGNORE' ) ); - $affected = $dbw->affectedRows(); + if ( $ids ) { + $dbw->delete( 'ipblocks', array( 'ipb_id' => $ids ), __METHOD__ ); + $dbw->insert( 'ipblocks', $row, __METHOD__, array( 'IGNORE' ) ); + $affected = $dbw->affectedRows(); + $this->mId = $dbw->insertId(); + } } - $this->mId = $dbw->insertId(); - if ( $affected ) { $auto_ipd_ids = $this->doRetroactiveAutoblock(); return array( 'id' => $this->mId, 'autoIds' => $auto_ipd_ids );