MediaWiki master
PoolWorkArticleViewOld.php
Go to the documentation of this file.
1<?php
21namespace MediaWiki\PoolCounter;
22
23use MediaWiki\Logger\Spi as LoggerSpi;
32
40 private $cache;
41
50 public function __construct(
51 string $workKey,
55 RevisionRenderer $revisionRenderer,
56 LoggerSpi $loggerSpi
57 ) {
58 parent::__construct( $workKey, $revision, $parserOptions, $revisionRenderer, $loggerSpi );
59
60 $this->cache = $cache;
61
62 $this->cacheable = true;
63 }
64
68 public function doWork() {
69 // T371713: Temporary statistics collection code to determine
70 // feasibility of Parsoid selective update
71 $sampleRate = MediaWikiServices::getInstance()->getMainConfig()->get(
73 );
74 $doSample = ( $sampleRate && mt_rand( 1, $sampleRate ) === 1 );
75
76 // Reduce effects of race conditions for slow parses (T48014)
77 $cacheTime = wfTimestampNow();
78
79 $status = $this->renderRevision(
80 null, /* don't attempt Parsoid selective updates on this path */
81 $doSample, 'PoolWorkArticleViewOld'
82 );
84 $output = $status->getValue();
85
86 if ( $output && $output->isCacheable() ) {
87 $this->cache->save( $output, $this->revision, $this->parserOptions, $cacheTime );
88 }
89
90 return $status;
91 }
92
96 public function getCachedWork() {
97 $parserOutput = $this->cache->get( $this->revision, $this->parserOptions );
98
99 return $parserOutput ? Status::newGood( $parserOutput ) : false;
100 }
101
102}
103
105class_alias( PoolWorkArticleViewOld::class, 'PoolWorkArticleViewOld' );
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
A class containing constants representing the names of configuration variables.
const ParsoidSelectiveUpdateSampleRate
Name constant for the ParsoidSelectiveUpdateSampleRate setting, for use with Config::get()
Service locator for MediaWiki core services.
static getInstance()
Returns the global default instance of the top level service locator.
Set options of the Parser.
ParserOutput is a rendering of a Content object or a message.
Cache for ParserOutput objects.
PoolWorkArticleView for an old revision of a page, using a simple cache.
__construct(string $workKey, RevisionOutputCache $cache, RevisionRecord $revision, ParserOptions $parserOptions, RevisionRenderer $revisionRenderer, LoggerSpi $loggerSpi)
PoolCounter protected work wrapping RenderedRevision->getRevisionParserOutput.
renderRevision(?ParserOutput $previousOutput=null, bool $doSample=false, string $sourceLabel='')
Render the given revision.
Page revision base class.
The RevisionRenderer service provides access to rendered output for revisions.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition Status.php:54
Service provider interface to create \Psr\Log\LoggerInterface objects.
Definition Spi.php:64