23use InvalidArgumentException;
54 private $wikiPageFactory;
56 private bool $triggerLinksUpdate;
85 bool $triggerLinksUpdate =
false
90 throw new InvalidArgumentException(
'$page parameter mismatches $revision parameter' );
95 $this->workKey = $workKey;
97 $this->parserCache = $parserCache;
98 $this->lbFactory = $lbFactory;
99 $this->chronologyProtector = $chronologyProtector;
100 $this->wikiPageFactory = $wikiPageFactory;
102 $this->triggerLinksUpdate = $triggerLinksUpdate;
114 $doSample = ( $sampleRate && mt_rand( 1, $sampleRate ) === 1 );
116 $previousOutput =
null;
117 if ( $this->parserOptions->getUseParsoid() || $doSample ) {
121 $previousOutput = $this->parserCache->getDirty( $this->page, $this->parserOptions ) ?:
null;
123 $status = $this->
renderRevision( $previousOutput, $doSample,
'PoolWorkArticleViewCurrent' );
125 $output = $status->getValue();
128 if ( $this->cacheable && $output->isCacheable() ) {
129 $this->parserCache->save(
136 if ( $this->triggerLinksUpdate ) {
137 $this->wikiPageFactory->newFromTitle( $this->page )->triggerOpportunisticLinksUpdate( $output );
148 $parserOutput = $this->parserCache->get( $this->page, $this->parserOptions );
150 $logger = $this->loggerSpi->getLogger(
'PoolWorkArticleView' );
151 $logger->debug( $parserOutput ?
'parser cache hit' :
'parser cache miss' );
153 return $parserOutput ? Status::newGood( $parserOutput ) :
false;
161 $parserOutput = $this->parserCache->getDirty( $this->page, $this->parserOptions );
163 $logger = $this->loggerSpi->getLogger(
'dirty' );
165 if ( !$parserOutput ) {
166 $logger->info(
'dirty missing' );
180 $lastWriteTime = $this->chronologyProtector->getTouched( $this->lbFactory->getMainLB() );
181 $cacheTime = MWTimestamp::convert( TS_UNIX, $parserOutput->getCacheTime() );
182 if ( $lastWriteTime && $cacheTime <= $lastWriteTime ) {
184 'declining to send dirty output since cache time ' .
185 '{cacheTime} is before last write time {lastWriteTime}',
187 'workKey' => $this->workKey,
188 'cacheTime' => $cacheTime,
189 'lastWriteTime' => $lastWriteTime,
199 $logger->info( $fast ?
'fast dirty output' :
'dirty output', [
'workKey' => $this->workKey ] );
201 $status = Status::newGood( $parserOutput );
202 $status->warning(
'view-pool-dirty-output' );
203 $status->warning( $fast ?
'view-pool-contention' :
'view-pool-overload' );
210class_alias( PoolWorkArticleViewCurrent::class,
'PoolWorkArticleViewCurrent' );
A class containing constants representing the names of configuration variables.
const ParsoidSelectiveUpdateSampleRate
Name constant for the ParsoidSelectiveUpdateSampleRate setting, for use with Config::get()
Service for creating WikiPage objects.
PoolWorkArticleView for the current revision of a page, using ParserCache.
__construct(string $workKey, PageRecord $page, RevisionRecord $revision, ParserOptions $parserOptions, RevisionRenderer $revisionRenderer, ParserCache $parserCache, ILBFactory $lbFactory, ChronologyProtector $chronologyProtector, LoggerSpi $loggerSpi, WikiPageFactory $wikiPageFactory, bool $cacheable=true, bool $triggerLinksUpdate=false)
PoolCounter protected work wrapping RenderedRevision->getRevisionParserOutput.
ParserOptions $parserOptions
renderRevision(?ParserOutput $previousOutput=null, bool $doSample=false, string $sourceLabel='')
Render the given revision.
Cache for ParserOutput objects corresponding to the latest page revisions.
Set options of the Parser.
getId( $wikiId=self::LOCAL)
Returns the page ID.