36 public function run() {
37 $updateRowsPerQuery = MediaWikiServices::getInstance()->getMainConfig()->get(
38 MainConfigNames::UpdateRowsPerQuery );
39 $userId = $this->params[
'userId'];
40 $maxWatchlistId = $this->params[
'maxWatchlistId'];
41 $batchSize = $updateRowsPerQuery;
43 $loadBalancer = MediaWikiServices::getInstance()->getDBLoadBalancer();
44 $dbw = $loadBalancer->getConnectionRef(
DB_PRIMARY );
45 $dbr = $loadBalancer->getConnectionRef(
DB_REPLICA );
48 if ( !$loadBalancer->waitForPrimaryPos( $dbr ) ) {
49 $this->
setLastError(
'Timed out waiting for replica to catch up before lock' );
54 $lockKey =
"{{$dbw->getDomainID()}}:ClearUserWatchlist:$userId";
55 $scopedLock = $dbw->getScopedLockAndFlush( $lockKey, __METHOD__, 10 );
57 $this->
setLastError(
"Could not acquire lock '$lockKey'" );
61 if ( !$loadBalancer->waitForPrimaryPos( $dbr ) ) {
62 $this->
setLastError(
'Timed out waiting for replica to catch up within lock' );
67 $dbr->flushSnapshot( __METHOD__ );
69 $watchlistIds = $dbr->newSelectQueryBuilder()
72 ->where( [
'wl_user' => $userId ] )
73 ->andWhere( $dbr->expr(
'wl_id',
'<=', $maxWatchlistId ) )
75 ->caller( __METHOD__ )->fetchFieldValues();
76 if ( count( $watchlistIds ) == 0 ) {
80 $dbw->newDeleteQueryBuilder()
81 ->deleteFrom(
'watchlist' )
82 ->where( [
'wl_id' => $watchlistIds ] )
83 ->caller( __METHOD__ )->execute();
84 if ( MediaWikiServices::getInstance()->getMainConfig()->
get( MainConfigNames::WatchlistExpiry ) ) {
85 $dbw->newDeleteQueryBuilder()
86 ->deleteFrom(
'watchlist_expiry' )
87 ->where( [
'we_item' => $watchlistIds ] )
88 ->caller( __METHOD__ )->execute();
92 $lbf = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
93 $lbf->commitPrimaryChanges( __METHOD__ );
96 if ( count( $watchlistIds ) === (
int)$batchSize ) {
99 MediaWikiServices::getInstance()->getJobQueueGroup()->push(
new self( $this->
getParams() ) );