41 public function run() {
44 $userId = $this->params[
'userId'];
45 $maxWatchlistId = $this->params[
'maxWatchlistId'];
46 $batchSize = $updateRowsPerQuery;
49 $dbw = $loadBalancer->getConnection(
DB_PRIMARY );
50 $dbr = $loadBalancer->getConnection(
DB_REPLICA );
53 if ( !$loadBalancer->waitForPrimaryPos( $dbr ) ) {
54 $this->
setLastError(
'Timed out waiting for replica to catch up before lock' );
59 $lockKey =
"{{$dbw->getDomainID()}}:ClearUserWatchlist:$userId";
60 $scopedLock = $dbw->getScopedLockAndFlush( $lockKey, __METHOD__, 10 );
62 $this->
setLastError(
"Could not acquire lock '$lockKey'" );
66 if ( !$loadBalancer->waitForPrimaryPos( $dbr ) ) {
67 $this->
setLastError(
'Timed out waiting for replica to catch up within lock' );
72 $dbr->flushSnapshot( __METHOD__ );
74 $watchlistIds = $dbr->newSelectQueryBuilder()
77 ->where( [
'wl_user' => $userId ] )
78 ->andWhere( $dbr->expr(
'wl_id',
'<=', $maxWatchlistId ) )
80 ->caller( __METHOD__ )->fetchFieldValues();
81 if ( count( $watchlistIds ) == 0 ) {
85 $dbw->newDeleteQueryBuilder()
86 ->deleteFrom(
'watchlist' )
87 ->where( [
'wl_id' => $watchlistIds ] )
88 ->caller( __METHOD__ )->execute();
90 $dbw->newDeleteQueryBuilder()
91 ->deleteFrom(
'watchlist_expiry' )
92 ->where( [
'we_item' => $watchlistIds ] )
93 ->caller( __METHOD__ )->execute();
98 $lbf->commitPrimaryChanges( __METHOD__ );
101 if ( count( $watchlistIds ) === (
int)$batchSize ) {