MediaWiki REL1_39
PoolWorkArticleViewCurrent.php
Go to the documentation of this file.
1<?php
21use MediaWiki\Logger\Spi as LoggerSpi;
27
34
36 private $workKey;
37
39 private $page;
40
42 private $parserCache;
43
45 private $lbFactory;
46
48 private $wikiPageFactory;
49
62 public function __construct(
63 string $workKey,
64 PageRecord $page,
65 RevisionRecord $revision,
66 ParserOptions $parserOptions,
67 RevisionRenderer $revisionRenderer,
68 ParserCache $parserCache,
69 ILBFactory $lbFactory,
70 LoggerSpi $loggerSpi,
71 WikiPageFactory $wikiPageFactory,
72 bool $cacheable = true
73 ) {
74 // TODO: Remove support for partially initialized RevisionRecord instances once
75 // Article no longer uses fake revisions.
76 if ( $revision->getPageId() && $revision->getPageId() !== $page->getId() ) {
77 throw new InvalidArgumentException( '$page parameter mismatches $revision parameter' );
78 }
79
80 parent::__construct( $workKey, $revision, $parserOptions, $revisionRenderer, $loggerSpi );
81
82 $this->workKey = $workKey;
83 $this->page = $page;
84 $this->parserCache = $parserCache;
85 $this->lbFactory = $lbFactory;
86 $this->wikiPageFactory = $wikiPageFactory;
87 $this->cacheable = $cacheable;
88 }
89
93 public function doWork() {
94 // Reduce effects of race conditions for slow parses (T48014)
95 $cacheTime = wfTimestampNow();
96
97 $status = $this->renderRevision();
99 $output = $status->getValue();
100
101 if ( $output ) {
102 if ( $this->cacheable && $output->isCacheable() ) {
103 $this->parserCache->save(
104 $output,
105 $this->page,
106 $this->parserOptions,
107 $cacheTime,
108 $this->revision->getId()
109 );
110 }
111
112 $this->wikiPageFactory->newFromTitle( $this->page )
113 ->triggerOpportunisticLinksUpdate( $output );
114 }
115
116 return $status;
117 }
118
122 public function getCachedWork() {
123 $parserOutput = $this->parserCache->get( $this->page, $this->parserOptions );
124
125 $logger = $this->loggerSpi->getLogger( 'PoolWorkArticleView' );
126 $logger->debug( $parserOutput ? 'parser cache hit' : 'parser cache miss' );
127
128 return $parserOutput ? Status::newGood( $parserOutput ) : false;
129 }
130
135 public function fallback( $fast ) {
136 $parserOutput = $this->parserCache->getDirty( $this->page, $this->parserOptions );
137
138 $logger = $this->loggerSpi->getLogger( 'dirty' );
139
140 if ( !$parserOutput ) {
141 $logger->info( 'dirty missing' );
142 return false;
143 }
144
145 if ( $fast ) {
146 /* Check if the stale response is from before the last write to the
147 * DB by this user. Declining to return a stale response in this
148 * case ensures that the user will see their own edit after page
149 * save.
150 *
151 * Note that the CP touch time is the timestamp of the shutdown of
152 * the save request, so there is a bias towards avoiding fast stale
153 * responses of potentially several seconds.
154 */
155 $lastWriteTime = $this->lbFactory->getChronologyProtectorTouched();
156 $cacheTime = MWTimestamp::convert( TS_UNIX, $parserOutput->getCacheTime() );
157 if ( $lastWriteTime && $cacheTime <= $lastWriteTime ) {
158 $logger->info(
159 'declining to send dirty output since cache time ' .
160 '{cacheTime} is before last write time {lastWriteTime}',
161 [
162 'workKey' => $this->workKey,
163 'cacheTime' => $cacheTime,
164 'lastWriteTime' => $lastWriteTime,
165 ]
166 );
167 // Forget this ParserOutput -- we will request it again if
168 // necessary in slow mode. There might be a newer entry
169 // available by that time.
170 return false;
171 }
172 }
173
174 $logger->info( $fast ? 'fast dirty output' : 'dirty output', [ 'workKey' => $this->workKey ] );
175
176 $status = Status::newGood( $parserOutput );
177 $status->warning( 'view-pool-dirty-output' );
178 $status->warning( $fast ? 'view-pool-contention' : 'view-pool-overload' );
179 return $status;
180 }
181
182}
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
Service for creating WikiPage objects.
Page revision base class.
getPageId( $wikiId=self::LOCAL)
Get the page ID.
The RevisionRenderer service provides access to rendered output for revisions.
Cache for ParserOutput objects corresponding to the latest page revisions.
Set options of the Parser.
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, LoggerSpi $loggerSpi, WikiPageFactory $wikiPageFactory, bool $cacheable=true)
PoolCounter protected work wrapping RenderedRevision->getRevisionParserOutput.
Service provider interface for \Psr\Log\LoggerInterface implementation libraries.
Definition Spi.php:38
Data record representing a page that is (or used to be, or could be) an editable page on a wiki.
getId( $wikiId=self::LOCAL)
Returns the page ID.
Manager of ILoadBalancer objects, and indirectly of IDatabase connections.