- # T98706: delete PK to avoid lock contention with RC delete log insertions
- $rcIds = array_merge( $rcIdsForTitle, $rcIdsForPage );
- if ( $rcIds ) {
- $this->mDb->delete( 'recentchanges', [ 'rc_id' => $rcIds ], __METHOD__ );
+ // T98706: delete by PK to avoid lock contention with RC delete log insertions
+ $rcIdBatches = array_chunk( array_merge( $rcIdsForTitle, $rcIdsForPage ), $batchSize );
+ foreach ( $rcIdBatches as $rcIdBatch ) {
+ $this->mDb->delete( 'recentchanges', [ 'rc_id' => $rcIdBatch ], __METHOD__ );
+ if ( count( $rcIdBatches ) > 1 ) {
+ $this->mDb->commit( __METHOD__, 'flush' );
+ wfGetLBFactory()->waitForReplication( [ 'wiki' => $this->mDb->getWikiID() ] );
+ }
+ }
+ }
+
+ // Commit and release the lock
+ ScopedCallback::consume( $scopedLock );
+ }
+
+ private function batchDeleteByPK( $table, array $conds, array $pk, $bSize ) {
+ $dbw = $this->mDb; // convenience
+ $res = $dbw->select( $table, $pk, $conds, __METHOD__ );
+
+ $pkDeleteConds = [];
+ foreach ( $res as $row ) {
+ $pkDeleteConds[] = $this->mDb->makeList( (array)$row, LIST_AND );
+ if ( count( $pkDeleteConds ) >= $bSize ) {
+ $dbw->delete( $table, $dbw->makeList( $pkDeleteConds, LIST_OR ), __METHOD__ );
+ $dbw->commit( __METHOD__, 'flush' );
+ wfGetLBFactory()->waitForReplication( [ 'wiki' => $dbw->getWikiID() ] );
+ $pkDeleteConds = [];