36 public function run() {
38 $userId = $this->params[
'userId'];
39 $maxWatchlistId = $this->params[
'maxWatchlistId'];
42 $loadBalancer = MediaWikiServices::getInstance()->getDBLoadBalancer();
43 $dbw = $loadBalancer->getConnectionRef(
DB_PRIMARY );
44 $dbr = $loadBalancer->getConnectionRef(
DB_REPLICA, [
'watchlist' ] );
47 if ( !$loadBalancer->waitForPrimaryPos(
$dbr ) ) {
48 $this->
setLastError(
'Timed out waiting for replica to catch up before lock' );
53 $lockKey =
"{{$dbw->getDomainID()}}:ClearUserWatchlist:$userId";
54 $scopedLock = $dbw->getScopedLockAndFlush( $lockKey, __METHOD__, 10 );
56 $this->
setLastError(
"Could not acquire lock '$lockKey'" );
60 if ( !$loadBalancer->waitForPrimaryPos(
$dbr ) ) {
61 $this->
setLastError(
'Timed out waiting for replica to catch up within lock' );
66 $dbr->flushSnapshot( __METHOD__ );
68 $watchlistIds =
$dbr->selectFieldValues(
73 'wl_id <= ' . $maxWatchlistId
77 'LIMIT' => $batchSize,
81 if ( count( $watchlistIds ) == 0 ) {
85 $dbw->delete(
'watchlist', [
'wl_id' => $watchlistIds ], __METHOD__ );
86 if ( MediaWikiServices::getInstance()->getMainConfig()->
get(
'WatchlistExpiry' ) ) {
87 $dbw->delete(
'watchlist_expiry', [
'we_item' => $watchlistIds ], __METHOD__ );
91 $lbf = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
92 $lbf->commitPrimaryChanges( __METHOD__ );
95 if ( count( $watchlistIds ) === (
int)$batchSize ) {
98 JobQueueGroup::singleton()->push(
new self( $this->
getParams() ) );