ResourceLoader::filter: use APC when running under HHVM
[lhc/web/wiklou.git] / includes / Block.php
index 0e2188d..d582201 100644 (file)
@@ -371,7 +371,7 @@ class Block {
                $this->mTimestamp = wfTimestamp( TS_MW, $row->ipb_timestamp );
                $this->mAuto = $row->ipb_auto;
                $this->mHideName = $row->ipb_deleted;
-               $this->mId = $row->ipb_id;
+               $this->mId = (int)$row->ipb_id;
                $this->mParentBlockId = $row->ipb_parent_block_id;
 
                // I wish I didn't have to do this
@@ -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 );