94 public function run() {
96 $lbFactory = $services->getDBLoadBalancerFactory();
97 $lb = $lbFactory->getMainLB();
100 $this->ticket = $lbFactory->getEmptyTransactionTicket( __METHOD__ );
102 $page = $services->getWikiPageFactory()->newFromID( $this->params[
'pageId'], IDBAccessObject::READ_LATEST );
104 $this->
setLastError(
"Could not find page #{$this->params['pageId']}" );
110 if ( !$lb->waitForPrimaryPos( $dbr ) ) {
111 $this->
setLastError(
"Timed out while pre-waiting for replica DB to catch up" );
116 $lockKey =
"{$dbw->getDomainID()}:CategoryMembershipChange:{$page->getId()}";
117 $scopedLock = $dbw->getScopedLockAndFlush( $lockKey, __METHOD__, 3 );
118 if ( !$scopedLock ) {
119 $this->
setLastError(
"Could not acquire lock '$lockKey'" );
124 if ( !$lb->waitForPrimaryPos( $dbr ) ) {
125 $this->
setLastError(
"Timed out while waiting for replica DB to catch up" );
129 $dbr->flushSnapshot( __METHOD__ );
131 $cutoffUnix =
wfTimestamp( TS_UNIX, $this->params[
'revTimestamp'] );
134 $cutoffUnix -= self::ENQUEUE_FUDGE_SEC;
138 $subQuery = $dbr->newSelectQueryBuilder()
140 ->from(
'recentchanges' )
141 ->where(
'rc_this_oldid = rev_id' )
142 ->andWhere( [
'rc_source' => RecentChange::SRC_CATEGORIZE ] );
143 $row = $dbr->newSelectQueryBuilder()
144 ->select( [
'rev_timestamp',
'rev_id' ] )
146 ->where( [
'rev_page' => $page->getId() ] )
147 ->andWhere( $dbr->expr(
'rev_timestamp',
'>=', $dbr->timestamp( $cutoffUnix ) ) )
148 ->andWhere(
new RawSQLExpression(
'EXISTS (' . $subQuery->getSQL() .
')' ) )
149 ->orderBy( [
'rev_timestamp',
'rev_id' ], SelectQueryBuilder::SORT_DESC )
150 ->caller( __METHOD__ )->fetchRow();
154 $cutoffUnix =
wfTimestamp( TS_UNIX, $row->rev_timestamp );
155 $lastRevId = (int)$row->rev_id;
162 $revisionStore = $services->getRevisionStore();
163 $res = $revisionStore->newSelectQueryBuilder( $dbr )
166 'rev_page' => $page->getId(),
167 $dbr->buildComparison(
'>', [
168 'rev_timestamp' => $dbr->timestamp( $cutoffUnix ),
169 'rev_id' => $lastRevId,
172 ->orderBy( [
'rev_timestamp',
'rev_id' ], SelectQueryBuilder::SORT_ASC )
173 ->caller( __METHOD__ )->fetchResultSet();
176 foreach ( $res as $row ) {
194 if ( $newRev->
isDeleted( RevisionRecord::DELETED_TEXT ) ) {
201 $oldRev = $services->getRevisionLookup()
202 ->getRevisionById( $newRev->
getParentId(), IDBAccessObject::READ_LATEST );
203 if ( !$oldRev || $oldRev->isDeleted( RevisionRecord::DELETED_TEXT ) ) {
211 $categoryChanges = $this->getExplicitCategoriesChanges( $page, $newRev, $oldRev );
212 [ $categoryInserts, $categoryDeletes ] = $categoryChanges;
213 if ( !$categoryInserts && !$categoryDeletes ) {
217 $blc = $services->getBacklinkCacheFactory()->getBacklinkCache(
$title );
219 $catMembChange->checkTemplateLinks();
224 foreach ( $categoryInserts as $categoryName ) {
225 $categoryTitle = Title::makeTitle(
NS_CATEGORY, $categoryName );
226 $catMembChange->triggerCategoryAddedNotification( $categoryTitle );
227 if ( $insertCount++ && ( $insertCount % $batchSize ) == 0 ) {
232 foreach ( $categoryDeletes as $categoryName ) {
233 $categoryTitle = Title::makeTitle(
NS_CATEGORY, $categoryName );
234 $catMembChange->triggerCategoryRemovedNotification( $categoryTitle );
235 if ( $insertCount++ && ( $insertCount++ % $batchSize ) == 0 ) {