44 public function run() {
46 $userId = $this->params[
'userId'];
47 $maxWatchlistId = $this->params[
'maxWatchlistId'];
50 $loadBalancer = MediaWikiServices::getInstance()->getDBLoadBalancer();
51 $dbw = $loadBalancer->getConnection(
DB_MASTER );
52 $dbr = $loadBalancer->getConnection(
DB_REPLICA, [
'watchlist' ] );
55 if ( !$loadBalancer->safeWaitForMasterPos(
$dbr ) ) {
56 $this->
setLastError(
'Timed out waiting for replica to catch up before lock' );
61 $lockKey =
"ClearUserWatchlistJob:$userId";
62 $scopedLock = $dbw->getScopedLockAndFlush( $lockKey, __METHOD__, 10 );
64 $this->
setLastError(
"Could not acquire lock '$lockKey'" );
68 if ( !$loadBalancer->safeWaitForMasterPos(
$dbr ) ) {
69 $this->
setLastError(
'Timed out waiting for replica to catch up within lock' );
74 $dbr->flushSnapshot( __METHOD__ );
76 $watchlistIds =
$dbr->selectFieldValues(
81 'wl_id <= ' . $maxWatchlistId
85 'ORDER BY' =>
'wl_id ASC',
86 'LIMIT' => $batchSize,
90 if ( count( $watchlistIds ) == 0 ) {
94 $dbw->delete(
'watchlist', [
'wl_id' => $watchlistIds ], __METHOD__ );
97 $lbf = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
98 $lbf->commitMasterChanges( __METHOD__ );
101 if ( count( $watchlistIds ) === (
int)$batchSize ) {
104 JobQueueGroup::singleton()->push(
new self( $this->
getTitle(), $this->
getParams() ) );