45 parent::__construct(
'categoryMembershipChange',
$title,
$params );
48 $this->removeDuplicates =
true;
51 public function run() {
52 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
53 $lb = $lbFactory->getMainLB();
56 $this->ticket = $lbFactory->getEmptyTransactionTicket( __METHOD__ );
60 $this->
setLastError(
"Could not find page #{$this->params['pageId']}" );
66 if ( !$lb->safeWaitForMasterPos(
$dbr ) ) {
67 $this->
setLastError(
"Timed out while pre-waiting for replica DB to catch up" );
72 $lockKey =
"CategoryMembershipUpdates:{$page->getId()}";
73 $scopedLock = $dbw->getScopedLockAndFlush( $lockKey, __METHOD__, 3 );
75 $this->
setLastError(
"Could not acquire lock '$lockKey'" );
80 if ( !$lb->safeWaitForMasterPos(
$dbr ) ) {
81 $this->
setLastError(
"Timed out while waiting for replica DB to catch up" );
85 $dbr->flushSnapshot( __METHOD__ );
87 $cutoffUnix =
wfTimestamp( TS_UNIX, $this->params[
'revTimestamp'] );
94 $row =
$dbr->selectRow(
96 [
'rev_timestamp',
'rev_id' ],
98 'rev_page' => $page->getId(),
99 'rev_timestamp >= ' .
$dbr->addQuotes(
$dbr->timestamp( $cutoffUnix ) ),
100 'EXISTS (' .
$dbr->selectSQLText(
104 'rc_this_oldid = rev_id',
107 'rc_cur_id = rev_page',
108 'rc_timestamp = rev_timestamp'
113 [
'ORDER BY' =>
'rev_timestamp DESC, rev_id DESC' ]
117 $cutoffUnix =
wfTimestamp( TS_UNIX, $row->rev_timestamp );
118 $lastRevId = (int)$row->rev_id;
125 $encCutoff =
$dbr->addQuotes(
$dbr->timestamp( $cutoffUnix ) );
131 'rev_page' => $page->getId(),
132 "rev_timestamp > $encCutoff" .
133 " OR (rev_timestamp = $encCutoff AND rev_id > $lastRevId)"
136 [
'ORDER BY' =>
'rev_timestamp ASC, rev_id ASC' ],
141 foreach (
$res as $row ) {
168 if ( !$oldRev->getContent() ) {
177 list( $categoryInserts, $categoryDeletes ) = $categoryChanges;
178 if ( !$categoryInserts && !$categoryDeletes ) {
183 $catMembChange->checkTemplateLinks();
185 $batchSize = $config->get(
'UpdateRowsPerQuery' );
188 foreach ( $categoryInserts
as $categoryName ) {
190 $catMembChange->triggerCategoryAddedNotification( $categoryTitle );
191 if ( $insertCount++ && ( $insertCount % $batchSize ) == 0 ) {
196 foreach ( $categoryDeletes
as $categoryName ) {
198 $catMembChange->triggerCategoryRemovedNotification( $categoryTitle );
199 if ( $insertCount++ && ( $insertCount++ % $batchSize ) == 0 ) {
215 $oldCategories = $oldRev
221 $categoryInserts = array_values( array_diff( $newCategories, $oldCategories ) );
222 $categoryDeletes = array_values( array_diff( $oldCategories, $newCategories ) );
224 return [ $categoryInserts, $categoryDeletes ];
235 $content =
$rev->getContent();
236 $options = $content->getContentHandler()->makeParserOptions(
'canonical' );
237 $options->setTimestamp( $parseTimestamp );
244 return array_map(
'strval', array_keys(
$output->getCategories() ) );
248 $info = parent::getDeduplicationInfo();
249 unset( $info[
'params'][
'revTimestamp'] );