37 public function run() {
38 $updateRowsPerQuery = MediaWikiServices::getInstance()->getMainConfig()->get(
39 MainConfigNames::UpdateRowsPerQuery );
40 $userId = $this->params[
'userId'];
41 $maxWatchlistId = $this->params[
'maxWatchlistId'];
42 $batchSize = $updateRowsPerQuery;
44 $loadBalancer = MediaWikiServices::getInstance()->getDBLoadBalancer();
45 $dbw = $loadBalancer->getConnectionRef(
DB_PRIMARY );
49 if ( !$loadBalancer->waitForPrimaryPos(
$dbr ) ) {
50 $this->
setLastError(
'Timed out waiting for replica to catch up before lock' );
55 $lockKey =
"{{$dbw->getDomainID()}}:ClearUserWatchlist:$userId";
56 $scopedLock = $dbw->getScopedLockAndFlush( $lockKey, __METHOD__, 10 );
58 $this->
setLastError(
"Could not acquire lock '$lockKey'" );
62 if ( !$loadBalancer->waitForPrimaryPos(
$dbr ) ) {
63 $this->
setLastError(
'Timed out waiting for replica to catch up within lock' );
68 $dbr->flushSnapshot( __METHOD__ );
70 $watchlistIds =
$dbr->selectFieldValues(
75 'wl_id <= ' . $maxWatchlistId
79 'LIMIT' => $batchSize,
83 if ( count( $watchlistIds ) == 0 ) {
87 $dbw->delete(
'watchlist', [
'wl_id' => $watchlistIds ], __METHOD__ );
88 if ( MediaWikiServices::getInstance()->getMainConfig()->
get(
89 MainConfigNames::WatchlistExpiry ) ) {
90 $dbw->delete(
'watchlist_expiry', [
'we_item' => $watchlistIds ], __METHOD__ );
94 $lbf = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
95 $lbf->commitPrimaryChanges( __METHOD__ );
98 if ( count( $watchlistIds ) === (
int)$batchSize ) {
101 MediaWikiServices::getInstance()->getJobQueueGroup()->push(
new self( $this->
getParams() ) );