83 public function run() {
84 $services = MediaWikiServices::getInstance();
85 $lbFactory = $services->getDBLoadBalancerFactory();
86 $lb = $lbFactory->getMainLB();
89 $this->ticket = $lbFactory->getEmptyTransactionTicket( __METHOD__ );
91 $page = $services->getWikiPageFactory()->newFromID( $this->params[
'pageId'], IDBAccessObject::READ_LATEST );
93 $this->
setLastError(
"Could not find page #{$this->params['pageId']}" );
99 if ( !$lb->waitForPrimaryPos( $dbr ) ) {
100 $this->
setLastError(
"Timed out while pre-waiting for replica DB to catch up" );
105 $lockKey =
"{$dbw->getDomainID()}:CategoryMembershipChange:{$page->getId()}";
106 $scopedLock = $dbw->getScopedLockAndFlush( $lockKey, __METHOD__, 3 );
107 if ( !$scopedLock ) {
108 $this->
setLastError(
"Could not acquire lock '$lockKey'" );
113 if ( !$lb->waitForPrimaryPos( $dbr ) ) {
114 $this->
setLastError(
"Timed out while waiting for replica DB to catch up" );
118 $dbr->flushSnapshot( __METHOD__ );
120 $cutoffUnix =
wfTimestamp( TS_UNIX, $this->params[
'revTimestamp'] );
123 $cutoffUnix -= self::ENQUEUE_FUDGE_SEC;
127 $subQuery = $dbr->newSelectQueryBuilder()
129 ->from(
'recentchanges' )
130 ->where(
'rc_this_oldid = rev_id' )
131 ->andWhere( [
'rc_source' => RecentChange::SRC_CATEGORIZE ] );
132 $row = $dbr->newSelectQueryBuilder()
133 ->select( [
'rev_timestamp',
'rev_id' ] )
135 ->where( [
'rev_page' => $page->
getId() ] )
136 ->andWhere( $dbr->expr(
'rev_timestamp',
'>=', $dbr->timestamp( $cutoffUnix ) ) )
137 ->andWhere(
'EXISTS (' . $subQuery->caller( __METHOD__ )->getSQL() .
')' )
138 ->orderBy( [
'rev_timestamp',
'rev_id' ], SelectQueryBuilder::SORT_DESC )
139 ->caller( __METHOD__ )->fetchRow();
143 $cutoffUnix =
wfTimestamp( TS_UNIX, $row->rev_timestamp );
144 $lastRevId = (int)$row->rev_id;
151 $revisionStore = $services->getRevisionStore();
152 $res = $revisionStore->newSelectQueryBuilder( $dbr )
155 'rev_page' => $page->
getId(),
156 $dbr->buildComparison(
'>', [
157 'rev_timestamp' => $dbr->timestamp( $cutoffUnix ),
158 'rev_id' => $lastRevId,
161 ->orderBy( [
'rev_timestamp',
'rev_id' ], SelectQueryBuilder::SORT_ASC )
162 ->caller( __METHOD__ )->fetchResultSet();
165 foreach ( $res as $row ) {
183 if ( $newRev->
isDeleted( RevisionRecord::DELETED_TEXT ) ) {
187 $services = MediaWikiServices::getInstance();
190 $oldRev = $services->getRevisionLookup()
191 ->getRevisionById( $newRev->
getParentId(), IDBAccessObject::READ_LATEST );
192 if ( !$oldRev || $oldRev->isDeleted( RevisionRecord::DELETED_TEXT ) ) {
200 $categoryChanges = $this->getExplicitCategoriesChanges( $page, $newRev, $oldRev );
201 [ $categoryInserts, $categoryDeletes ] = $categoryChanges;
202 if ( !$categoryInserts && !$categoryDeletes ) {
206 $blc = $services->getBacklinkCacheFactory()->getBacklinkCache(
$title );
208 $catMembChange->checkTemplateLinks();
210 $batchSize = $services->getMainConfig()->get( MainConfigNames::UpdateRowsPerQuery );
213 foreach ( $categoryInserts as $categoryName ) {
214 $categoryTitle = Title::makeTitle(
NS_CATEGORY, $categoryName );
215 $catMembChange->triggerCategoryAddedNotification( $categoryTitle );
216 if ( $insertCount++ && ( $insertCount % $batchSize ) == 0 ) {
221 foreach ( $categoryDeletes as $categoryName ) {
222 $categoryTitle = Title::makeTitle(
NS_CATEGORY, $categoryName );
223 $catMembChange->triggerCategoryRemovedNotification( $categoryTitle );
224 if ( $insertCount++ && ( $insertCount++ % $batchSize ) == 0 ) {