X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Fjobqueue%2Futils%2FPurgeJobUtils.php;h=ba80c8e450a9f320ff99c2b82d56ced8c5218dc3;hp=5eafcb384df75939b428cf542dc78c8d1ae4b4eb;hb=d5a7166771613dfe4ed9fb75fa5efeced6134bd1;hpb=75f7a86b2ef5f6e89f9439ce764d0290d1c2011a diff --git a/includes/jobqueue/utils/PurgeJobUtils.php b/includes/jobqueue/utils/PurgeJobUtils.php index 5eafcb384d..ba80c8e450 100644 --- a/includes/jobqueue/utils/PurgeJobUtils.php +++ b/includes/jobqueue/utils/PurgeJobUtils.php @@ -20,6 +20,7 @@ * * @file */ +use Wikimedia\Rdbms\IDatabase; use MediaWiki\MediaWikiServices; class PurgeJobUtils { @@ -36,42 +37,45 @@ class PurgeJobUtils { return; } - $dbw->onTransactionIdle( function() use ( $dbw, $namespace, $dbkeys ) { - $services = MediaWikiServices::getInstance(); - $lbFactory = $services->getDBLoadBalancerFactory(); - // Determine which pages need to be updated. - // This is necessary to prevent the job queue from smashing the DB with - // large numbers of concurrent invalidations of the same page. - $now = $dbw->timestamp(); - $ids = $dbw->selectFieldValues( - 'page', - 'page_id', - [ - 'page_namespace' => $namespace, - 'page_title' => $dbkeys, - 'page_touched < ' . $dbw->addQuotes( $now ) - ], - __METHOD__ - ); - - if ( !$ids ) { - return; - } - - $batchSize = $services->getMainConfig()->get( 'UpdateRowsPerQuery' ); - $ticket = $lbFactory->getEmptyTransactionTicket( __METHOD__ ); - foreach ( array_chunk( $ids, $batchSize ) as $idBatch ) { - $dbw->update( + $dbw->onTransactionIdle( + function () use ( $dbw, $namespace, $dbkeys ) { + $services = MediaWikiServices::getInstance(); + $lbFactory = $services->getDBLoadBalancerFactory(); + // Determine which pages need to be updated. + // This is necessary to prevent the job queue from smashing the DB with + // large numbers of concurrent invalidations of the same page. + $now = $dbw->timestamp(); + $ids = $dbw->selectFieldValues( 'page', - [ 'page_touched' => $now ], + 'page_id', [ - 'page_id' => $idBatch, - 'page_touched < ' . $dbw->addQuotes( $now ) // handle races + 'page_namespace' => $namespace, + 'page_title' => $dbkeys, + 'page_touched < ' . $dbw->addQuotes( $now ) ], __METHOD__ ); - $lbFactory->commitAndWaitForReplication( __METHOD__, $ticket ); - } - } ); + + if ( !$ids ) { + return; + } + + $batchSize = $services->getMainConfig()->get( 'UpdateRowsPerQuery' ); + $ticket = $lbFactory->getEmptyTransactionTicket( __METHOD__ ); + foreach ( array_chunk( $ids, $batchSize ) as $idBatch ) { + $dbw->update( + 'page', + [ 'page_touched' => $now ], + [ + 'page_id' => $idBatch, + 'page_touched < ' . $dbw->addQuotes( $now ) // handle races + ], + __METHOD__ + ); + $lbFactory->commitAndWaitForReplication( __METHOD__, $ticket ); + } + }, + __METHOD__ + ); } }