Do not run ipblocks cleanup randomly, just do it all the time
authorAmir Sarabadani <ladsgroup@gmail.com>
Fri, 23 Feb 2018 16:58:58 +0000 (17:58 +0100)
committerAaron Schulz <aschulz@wikimedia.org>
Wed, 28 Feb 2018 03:45:03 +0000 (03:45 +0000)
It's a deferred update and the number of blocks are small

Change-Id: I75e0b7dc38b22f8aa7453582d535a8ab8121fd1a

includes/Block.php

index bdc6702..e0b63ff 100644 (file)
@@ -526,10 +526,7 @@ class Block {
                        $dbw = wfGetDB( DB_MASTER );
                }
 
-               # Periodic purge via commit hooks
-               if ( mt_rand( 0, 9 ) == 0 ) {
-                       self::purgeExpired();
-               }
+               self::purgeExpired();
 
                $row = $this->getDatabaseArray( $dbw );
 
@@ -1119,11 +1116,14 @@ class Block {
                        wfGetDB( DB_MASTER ),
                        __METHOD__,
                        function ( IDatabase $dbw, $fname ) {
-                               $dbw->delete(
-                                       'ipblocks',
+                               $ids = $dbw->selectFieldValues( 'ipblocks',
+                                       'ipb_id',
                                        [ 'ipb_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ],
                                        $fname
                                );
+                               if ( $ids ) {
+                                       $dbw->delete( 'ipblocks', [ 'ipb_id' => $ids ], $fname );
+                               }
                        }
                ) );
        }