*
* @file
*/
+use MediaWiki\MediaWikiServices;
/**
* @cond file_level_code
'refreshLinksPrioritized' => RefreshLinksJob::class,
'refreshLinksDynamic' => RefreshLinksJob::class,
'activityUpdateJob' => ActivityUpdateJob::class,
- 'categoryMembershipChange' => CategoryMembershipChangeJob::class,
+ 'categoryMembershipChange' => function ( Title $title, $params = [] ) {
+ $pc = MediaWikiServices::getInstance()->getParserCache();
+ return new CategoryMembershipChangeJob( $pc, $title, $params );
+ },
'clearUserWatchlist' => ClearUserWatchlistJob::class,
'cdnPurge' => CdnPurgeJob::class,
'userGroupExpiry' => UserGroupExpiryJob::class,
// the recent change entry (also done via deferred updates) and carry over any
// bot/deletion/IP flags, ect.
$this->jobQueueGroup->lazyPush(
- new CategoryMembershipChangeJob(
+ CategoryMembershipChangeJob::newSpec(
$this->getTitle(),
- [
- 'pageId' => $this->getPageId(),
- 'revTimestamp' => $this->revision->getTimestamp(),
- ]
+ $this->revision->getTimestamp()
)
);
}
const ENQUEUE_FUDGE_SEC = 60;
- public function __construct( Title $title, array $params ) {
+ /**
+ * @var ParserCache
+ */
+ private $parserCache;
+
+ /**
+ * @param Title $title The title of the page for which to update category emmbership.
+ * @param string $revisionTimestamp The timestamp of the new revision that triggered the job.
+ * @return JobSpecification
+ */
+ public static function newSpec( Title $title, $revisionTimestamp ) {
+ return new JobSpecification(
+ 'categoryMembershipChange',
+ [
+ 'pageId' => $title->getArticleID(),
+ 'revTimestamp' => $revisionTimestamp,
+ ],
+ [],
+ $title
+ );
+ }
+
+ /**
+ * Constructor for use by the Job Queue infrastructure.
+ * @note Don't call this when queueing a new instance, use newSpec() instead.
+ */
+ public function __construct( ParserCache $parserCache, Title $title, array $params ) {
parent::__construct( 'categoryMembershipChange', $title, $params );
// Only need one job per page. Note that ENQUEUE_FUDGE_SEC handles races where an
// older revision job gets inserted while the newer revision job is de-duplicated.
$this->removeDuplicates = true;
+ $this->parserCache = $parserCache;
}
public function run() {
$options = $page->makeParserOptions( 'canonical' );
$options->setTimestamp( $parseTimestamp );
- // This could possibly use the parser cache if it checked the revision ID,
- // but that's more complicated than it's worth.
- $output = $renderer->getRenderedRevision( $rev->getRevisionRecord(), $options )
- ->getRevisionParserOutput();
+ $output = $rev->isCurrent() ? $this->parserCache->get( $page, $options ) : null;
+
+ if ( !$output || $output->getCacheRevisionId() !== $rev->getId() ) {
+ $output = $renderer->getRenderedRevision( $rev->getRevisionRecord(), $options )
+ ->getRevisionParserOutput();
+ }
// array keys will cast numeric category names to ints
// so we need to cast them back to strings to avoid breaking things!
* @return RecentChange|null
*/
private function getCategorizeRecentChangeForRevId( $revId ) {
- return RecentChange::newFromConds(
+ $rc = RecentChange::newFromConds(
[
'rc_type' => RC_CATEGORIZE,
'rc_this_oldid' => $revId,
],
__METHOD__
);
+
+ $this->assertNotNull( $rc, 'rev__id = ' . $revId );
+ return $rc;
}
public function testRun_normalCategoryAddedAndRemoved() {