35 private LoggerInterface $logger;
52 parent::__construct(
'parsoidCachePrewarm', $params );
55 $this->logger = LoggerFactory::getInstance(
'ParsoidCachePrewarmJob' );
56 $this->parsoidOutputAccess = $parsoidOutputAccess;
57 $this->pageLookup = $pageLookup;
58 $this->revisionLookup = $revisionLookup;
77 if ( !is_int( $page ) && !( $page instanceof
PageRecord ) ) {
78 throw new InvalidArgumentException(
79 '$page must be a int or a PageRecord object.' );
82 $pageId = is_int( $page ) ? $page : $page->getId();
84 $params += [
'options' => 0 ];
88 $pageTouched = $page->getTouched();
89 $params += self::newRootJobParams(
90 "parsoidCachePrewarm:$pageId:$revisionId:$pageTouched:{$params['options']}"
92 $params += [
'page_touched' => $pageTouched ];
93 $opts = [
'removeDuplicates' =>
true ];
97 'parsoidCachePrewarm',
99 'revId' => $revisionId,
106 private function doParsoidCacheUpdate() {
107 $page = $this->pageLookup->getPageById( $this->params[
'pageId'] );
108 $revId = $this->params[
'revId'];
110 if ( $page ===
null ) {
112 $this->logger->info(
"Page with ID {$this->params['pageId']} not found" );
116 if ( $page->getLatest() !== $revId ) {
118 'ParsoidCachePrewarmJob: The ID of the new revision does not match the page\'s current revision ID'
123 $rev = $this->revisionLookup->getRevisionById( $revId );
130 $renderReason = $this->params[
'causeAction'] ?? $this->command;
131 $parserOpts->setRenderReason( $renderReason );
133 $mainSlot = $rev->getSlot( SlotRecord::MAIN );
134 if ( !$this->parsoidOutputAccess->supportsContentModel( $mainSlot->getModel() ) ) {
135 $this->logger->debug( __METHOD__ .
': Parsoid does not support content model ' . $mainSlot->getModel() );
139 $this->logger->debug( __METHOD__ .
': generating Parsoid output' );
142 $options = $this->params[
'options'] ?? 0;
145 $status = $this->parsoidOutputAccess->getParserOutput(
149 $options | ParsoidOutputAccess::OPT_LOG_LINT_DATA
152 if ( !$status->isOK() ) {
153 $this->logger->error( __METHOD__ .
': Parsoid error', [
154 'errors' => $status->getErrors(),
155 'page' => $page->getDBkey(),
156 'rev' => $rev->getId(),
162 $this->doParsoidCacheUpdate();