MediaWiki REL1_37
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
49
61 public function __construct(
62 string $workKey,
63 PageRecord $page,
64 RevisionRecord $revision,
65 ParserOptions $parserOptions,
66 RevisionRenderer $revisionRenderer,
67 ParserCache $parserCache,
68 ILBFactory $lbFactory,
69 LoggerSpi $loggerSpi,
70 WikiPageFactory $wikiPageFactory
71 ) {
72 // TODO: Remove support for partially initialized RevisionRecord instances once
73 // Article no longer uses fake revisions.
74 if ( $revision->getPageId() && $revision->getPageId() !== $page->getId() ) {
75 throw new InvalidArgumentException( '$page parameter mismatches $revision parameter' );
76 }
77
78 parent::__construct( $workKey, $revision, $parserOptions, $revisionRenderer, $loggerSpi );
79
80 $this->workKey = $workKey;
81 $this->page = $page;
82 $this->parserCache = $parserCache;
83 $this->lbFactory = $lbFactory;
84 $this->wikiPageFactory = $wikiPageFactory;
85 $this->cacheable = true;
86 }
87
92 protected function saveInCache( ParserOutput $output, string $cacheTime ) {
93 $this->parserCache->save(
94 $output,
95 $this->page,
96 $this->parserOptions,
97 $cacheTime,
98 $this->revision->getId()
99 );
100 }
101
105 protected function afterWork( ParserOutput $output ) {
106 $this->wikiPageFactory->newFromTitle( $this->page )
107 ->triggerOpportunisticLinksUpdate( $this->parserOutput );
108 }
109
113 public function getCachedWork() {
114 $this->parserOutput = $this->parserCache->get( $this->page, $this->parserOptions );
115
116 $logger = $this->getLogger();
117 if ( $this->parserOutput === false ) {
118 $logger->debug( 'parser cache miss' );
119 return false;
120 } else {
121 $logger->debug( 'parser cache hit' );
122 return true;
123 }
124 }
125
130 public function fallback( $fast ) {
131 $this->parserOutput = $this->parserCache->getDirty( $this->page, $this->parserOptions );
132
133 $logger = $this->getLogger( 'dirty' );
134
135 $fastMsg = '';
136 if ( $this->parserOutput && $fast ) {
137 /* Check if the stale response is from before the last write to the
138 * DB by this user. Declining to return a stale response in this
139 * case ensures that the user will see their own edit after page
140 * save.
141 *
142 * Note that the CP touch time is the timestamp of the shutdown of
143 * the save request, so there is a bias towards avoiding fast stale
144 * responses of potentially several seconds.
145 */
146 $lastWriteTime = $this->lbFactory->getChronologyProtectorTouched();
147 $cacheTime = MWTimestamp::convert( TS_UNIX, $this->parserOutput->getCacheTime() );
148 if ( $lastWriteTime && $cacheTime <= $lastWriteTime ) {
149 $logger->info(
150 'declining to send dirty output since cache time ' .
151 '{cacheTime} is before last write time {lastWriteTime}',
152 [
153 'workKey' => $this->workKey,
154 'cacheTime' => $cacheTime,
155 'lastWriteTime' => $lastWriteTime,
156 ]
157 );
158 // Forget this ParserOutput -- we will request it again if
159 // necessary in slow mode. There might be a newer entry
160 // available by that time.
161 $this->parserOutput = false;
162 return false;
163 }
164 $this->isFast = true;
165 $fastMsg = 'fast ';
166 }
167
168 if ( $this->parserOutput === false ) {
169 $logger->info( 'dirty missing' );
170 return false;
171 } else {
172 $logger->info( "{$fastMsg}dirty output", [ 'workKey' => $this->workKey ] );
173 $this->isDirty = true;
174 return true;
175 }
176 }
177}
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)
saveInCache(ParserOutput $output, string $cacheTime)
PoolCounter protected work wrapping RenderedRevision->getRevisionParserOutput.
getLogger( $name='PoolWorkArticleView')
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.
An interface for generating database load balancers.