}
protected function purgeExpiredRows() {
- global $wgRCMaxAge;
+ global $wgRCMaxAge, $wgUpdateRowsPerQuery;
$lockKey = wfWikiID() . ':recentchanges-prune';
return; // already in progress
}
- $batchSize = 100; // avoid slave lag
+ $factory = wfGetLBFactory();
+ $ticket = $factory->getEmptyTransactionTicket( __METHOD__ );
$cutoff = $dbw->timestamp( time() - $wgRCMaxAge );
do {
$rcIds = $dbw->selectFieldValues( 'recentchanges',
'rc_id',
[ 'rc_timestamp < ' . $dbw->addQuotes( $cutoff ) ],
__METHOD__,
- [ 'LIMIT' => $batchSize ]
+ [ 'LIMIT' => $wgUpdateRowsPerQuery ]
);
if ( $rcIds ) {
$dbw->delete( 'recentchanges', [ 'rc_id' => $rcIds ], __METHOD__ );
- }
- // Commit in chunks to avoid slave lag
- $dbw->commit( __METHOD__, 'flush' );
-
- if ( count( $rcIds ) === $batchSize ) {
// There might be more, so try waiting for slaves
try {
- wfGetLBFactory()->waitForReplication( [ 'timeout' => 3 ] );
+ $factory->commitAndWaitForReplication(
+ __METHOD__, $ticket, [ 'timeout' => 3 ]
+ );
} catch ( DBReplicationWaitError $e ) {
// Another job will continue anyway
break;
// JobRunner uses DBO_TRX, but doesn't call begin/commit itself;
// onTransactionIdle() will run immediately since there is no trx.
$dbw->onTransactionIdle( function() use ( $dbw, $days, $window ) {
+ $factory = wfGetLBFactory();
+ $ticket = $factory->getEmptyTransactionTicket( __METHOD__ );
// Avoid disconnect/ping() cycle that makes locks fall off
$dbw->setSessionOptions( [ 'connTimeout' => 900 ] );
}
foreach ( array_chunk( $newRows, 500 ) as $rowBatch ) {
$dbw->insert( 'querycachetwo', $rowBatch, __METHOD__ );
- wfGetLBFactory()->waitForReplication();
+ $factory->commitAndWaitForReplication( __METHOD__, $ticket );
}
}