21 parent::__construct(
'clearUserWatchlist', $params );
23 $this->removeDuplicates =
true;
33 return new self( [
'userId' => $user->
getId(),
'maxWatchlistId' => $maxWatchlistId ] );
36 public function run() {
38 $userId = $this->params[
'userId'];
39 $maxWatchlistId = $this->params[
'maxWatchlistId'];
42 $loadBalancer = MediaWikiServices::getInstance()->getDBLoadBalancer();
43 $dbw = $loadBalancer->getConnectionRef(
DB_MASTER );
44 $dbr = $loadBalancer->getConnectionRef(
DB_REPLICA, [
'watchlist' ] );
47 if ( !$loadBalancer->waitForMasterPos(
$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->waitForMasterPos(
$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 'ORDER BY' =>
'wl_id ASC',
78 'LIMIT' => $batchSize,
82 if ( count( $watchlistIds ) == 0 ) {
86 $dbw->delete(
'watchlist', [
'wl_id' => $watchlistIds ], __METHOD__ );
89 $lbf = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
90 $lbf->commitMasterChanges( __METHOD__ );
93 if ( count( $watchlistIds ) === (
int)$batchSize ) {
103 $info = parent::getDeduplicationInfo();
105 unset( $info[
'namespace'] );
106 unset( $info[
'title'] );
Job to clear a users watchlist in batches.
Class to both describe a background job and handle jobs.
getDeduplicationInfo()
Subclasses may need to override this to make duplication detection work.
__construct(array $params)
$wgUpdateRowsPerQuery
Number of rows to update per query.
static singleton( $domain=false)
array $params
Array of job parameters.
static newForUser(UserIdentity $user, $maxWatchlistId)
Interface for generic jobs only uses the parameters field and are JSON serializable.