43 parent::__construct(
'categoryMembershipChange',
$title,
$params );
46 $this->removeDuplicates =
true;
49 public function run() {
50 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
51 $lb = $lbFactory->getMainLB();
54 $this->ticket = $lbFactory->getEmptyTransactionTicket( __METHOD__ );
58 $this->
setLastError(
"Could not find page #{$this->params['pageId']}" );
63 $lockKey =
"CategoryMembershipUpdates:{$page->getId()}";
64 $scopedLock = $dbw->getScopedLockAndFlush( $lockKey, __METHOD__, 3 );
66 $this->
setLastError(
"Could not acquire lock '$lockKey'" );
72 if ( !$lb->safeWaitForMasterPos(
$dbr ) ) {
73 $this->
setLastError(
"Timed out while waiting for replica DB to catch up" );
77 $dbr->flushSnapshot( __METHOD__ );
79 $cutoffUnix =
wfTimestamp( TS_UNIX, $this->params[
'revTimestamp'] );
85 $row =
$dbr->selectRow(
86 [
'revision',
'recentchanges' ],
87 [
'rev_timestamp',
'rev_id' ],
89 'rev_page' => $page->getId(),
90 'rev_timestamp >= ' .
$dbr->addQuotes(
$dbr->timestamp( $cutoffUnix ) )
93 [
'ORDER BY' =>
'rev_timestamp DESC, rev_id DESC' ],
98 'rc_this_oldid = rev_id',
101 'rc_cur_id = rev_page',
102 'rc_timestamp >= rev_timestamp'
109 $cutoffUnix =
wfTimestamp( TS_UNIX, $row->rev_timestamp );
110 $lastRevId = (int)$row->rev_id;
117 $encCutoff =
$dbr->addQuotes(
$dbr->timestamp( $cutoffUnix ) );
122 'rev_page' => $page->getId(),
123 "rev_timestamp > $encCutoff" .
124 " OR (rev_timestamp = $encCutoff AND rev_id > $lastRevId)"
127 [
'ORDER BY' =>
'rev_timestamp ASC, rev_id ASC' ]
131 foreach (
$res as $row ) {
158 if ( !$oldRev->getContent() ) {
167 list( $categoryInserts, $categoryDeletes ) = $categoryChanges;
168 if ( !$categoryInserts && !$categoryDeletes ) {
173 $catMembChange->checkTemplateLinks();
175 $batchSize = $config->get(
'UpdateRowsPerQuery' );
178 foreach ( $categoryInserts
as $categoryName ) {
180 $catMembChange->triggerCategoryAddedNotification( $categoryTitle );
181 if ( $insertCount++ && ( $insertCount % $batchSize ) == 0 ) {
186 foreach ( $categoryDeletes
as $categoryName ) {
188 $catMembChange->triggerCategoryRemovedNotification( $categoryTitle );
189 if ( $insertCount++ && ( $insertCount++ % $batchSize ) == 0 ) {
205 $oldCategories = $oldRev
211 $categoryInserts = array_values( array_diff( $newCategories, $oldCategories ) );
212 $categoryDeletes = array_values( array_diff( $oldCategories, $newCategories ) );
214 return [ $categoryInserts, $categoryDeletes ];
225 $content =
$rev->getContent();
226 $options = $content->getContentHandler()->makeParserOptions(
'canonical' );
227 $options->setTimestamp( $parseTimestamp );
234 return array_map(
'strval', array_keys(
$output->getCategories() ) );
238 $info = parent::getDeduplicationInfo();
239 unset( $info[
'params'][
'revTimestamp'] );