40 public function run() {
43 $userId = $this->params[
'userId'];
44 $maxWatchlistId = $this->params[
'maxWatchlistId'];
45 $batchSize = $updateRowsPerQuery;
48 $dbw = $loadBalancer->getConnection(
DB_PRIMARY );
49 $dbr = $loadBalancer->getConnection(
DB_REPLICA );
52 if ( !$loadBalancer->waitForPrimaryPos( $dbr ) ) {
53 $this->
setLastError(
'Timed out waiting for replica to catch up before lock' );
58 $lockKey =
"{{$dbw->getDomainID()}}:ClearUserWatchlist:$userId";
59 $scopedLock = $dbw->getScopedLockAndFlush( $lockKey, __METHOD__, 10 );
61 $this->
setLastError(
"Could not acquire lock '$lockKey'" );
65 if ( !$loadBalancer->waitForPrimaryPos( $dbr ) ) {
66 $this->
setLastError(
'Timed out waiting for replica to catch up within lock' );
71 $dbr->flushSnapshot( __METHOD__ );
73 $watchlistIds = $dbr->newSelectQueryBuilder()
76 ->where( [
'wl_user' => $userId ] )
77 ->andWhere( $dbr->expr(
'wl_id',
'<=', $maxWatchlistId ) )
79 ->caller( __METHOD__ )->fetchFieldValues();
80 if ( count( $watchlistIds ) == 0 ) {
84 $dbw->newDeleteQueryBuilder()
85 ->deleteFrom(
'watchlist' )
86 ->where( [
'wl_id' => $watchlistIds ] )
87 ->caller( __METHOD__ )->execute();
89 $dbw->newDeleteQueryBuilder()
90 ->deleteFrom(
'watchlist_expiry' )
91 ->where( [
'we_item' => $watchlistIds ] )
92 ->caller( __METHOD__ )->execute();
97 $lbf->commitPrimaryChanges( __METHOD__ );
100 if ( count( $watchlistIds ) === (
int)$batchSize ) {