56 'categoryMembershipChange',
59 'revTimestamp' => $revisionTimestamp,
74 parent::__construct(
'categoryMembershipChange',
$title,
$params );
77 $this->removeDuplicates =
true;
81 public function run() {
82 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
83 $lb = $lbFactory->getMainLB();
84 $dbw = $lb->getConnectionRef(
DB_MASTER );
86 $this->ticket = $lbFactory->getEmptyTransactionTicket( __METHOD__ );
90 $this->
setLastError(
"Could not find page #{$this->params['pageId']}" );
96 if ( !$lb->waitForMasterPos(
$dbr ) ) {
97 $this->
setLastError(
"Timed out while pre-waiting for replica DB to catch up" );
102 $lockKey =
"{$dbw->getDomainID()}:CategoryMembershipChange:{$page->getId()}";
103 $scopedLock = $dbw->getScopedLockAndFlush( $lockKey, __METHOD__, 3 );
104 if ( !$scopedLock ) {
105 $this->
setLastError(
"Could not acquire lock '$lockKey'" );
110 if ( !$lb->waitForMasterPos(
$dbr ) ) {
111 $this->
setLastError(
"Timed out while waiting for replica DB to catch up" );
115 $dbr->flushSnapshot( __METHOD__ );
117 $cutoffUnix =
wfTimestamp( TS_UNIX, $this->params[
'revTimestamp'] );
124 $row =
$dbr->selectRow(
126 [
'rev_timestamp',
'rev_id' ],
128 'rev_page' => $page->getId(),
129 'rev_timestamp >= ' .
$dbr->addQuotes(
$dbr->timestamp( $cutoffUnix ) ),
130 'EXISTS (' .
$dbr->selectSQLText(
134 'rc_this_oldid = rev_id',
137 'rc_cur_id = rev_page',
138 'rc_timestamp = rev_timestamp'
143 [
'ORDER BY' =>
'rev_timestamp DESC, rev_id DESC' ]
147 $cutoffUnix =
wfTimestamp( TS_UNIX, $row->rev_timestamp );
148 $lastRevId = (int)$row->rev_id;
155 $encCutoff =
$dbr->addQuotes(
$dbr->timestamp( $cutoffUnix ) );
161 'rev_page' => $page->getId(),
162 "rev_timestamp > $encCutoff" .
163 " OR (rev_timestamp = $encCutoff AND rev_id > $lastRevId)"
166 [
'ORDER BY' =>
'rev_timestamp ASC, rev_id ASC' ],
171 foreach (
$res as $row ) {
198 if ( !$oldRev || !$oldRev->getContent() ) {
207 list( $categoryInserts, $categoryDeletes ) = $categoryChanges;
208 if ( !$categoryInserts && !$categoryDeletes ) {
213 $catMembChange->checkTemplateLinks();
215 $batchSize = $config->get(
'UpdateRowsPerQuery' );
218 foreach ( $categoryInserts as $categoryName ) {
220 $catMembChange->triggerCategoryAddedNotification( $categoryTitle );
221 if ( $insertCount++ && ( $insertCount % $batchSize ) == 0 ) {
226 foreach ( $categoryDeletes as $categoryName ) {
228 $catMembChange->triggerCategoryRemovedNotification( $categoryTitle );
229 if ( $insertCount++ && ( $insertCount++ % $batchSize ) == 0 ) {
245 $oldCategories = $oldRev
251 $categoryInserts = array_values( array_diff( $newCategories, $oldCategories ) );
252 $categoryDeletes = array_values( array_diff( $oldCategories, $newCategories ) );
254 return [ $categoryInserts, $categoryDeletes ];
265 $renderer = MediaWikiServices::getInstance()->getRevisionRenderer();
267 $options->setTimestamp( $parseTimestamp );
269 $output = $rev->
isCurrent() ? $this->parserCache->get( $page, $options ) :
null;
273 ->getRevisionParserOutput();
278 return array_map(
'strval', array_keys(
$output->getCategories() ) );
282 $info = parent::getDeduplicationInfo();
283 unset( $info[
'params'][
'revTimestamp'] );