X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FBlock.php;h=873a26d86f82db3308a89bbd2be680e1557b8b5c;hb=a21cc4597c21d8216dc583f63397f035f1f83343;hp=4698f457d67576d558fb17890268cca55208b561;hpb=6b66221bda831554bb40437a925e2625232f81ce;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Block.php b/includes/Block.php index 4698f457d6..873a26d86f 100644 --- a/includes/Block.php +++ b/includes/Block.php @@ -442,19 +442,33 @@ class Block { $dbw = wfGetDB( DB_MASTER ); } - # Don't collide with expired blocks - Block::purgeExpired(); + # Periodic purge via commit hooks + if ( mt_rand( 0, 9 ) == 0 ) { + Block::purgeExpired(); + } $row = $this->getDatabaseArray(); $row['ipb_id'] = $dbw->nextSequenceValue( "ipblocks_ipb_id_seq" ); - $dbw->insert( - 'ipblocks', - $row, - __METHOD__, - array( 'IGNORE' ) - ); + $dbw->insert( 'ipblocks', $row, __METHOD__, array( 'IGNORE' ) ); $affected = $dbw->affectedRows(); + + # Don't collide with expired blocks. + # Do this after trying to insert to avoid pointless gap locks. + if ( !$affected ) { + $dbw->delete( 'ipblocks', + array( + 'ipb_address' => $row['ipb_address'], + 'ipb_user' => $row['ipb_user'], + 'ipb_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) + ), + __METHOD__ + ); + + $dbw->insert( 'ipblocks', $row, __METHOD__, array( 'IGNORE' ) ); + $affected = $dbw->affectedRows(); + } + $this->mId = $dbw->insertId(); if ( $affected ) {