Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
75.00% |
9 / 12 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
PoolWorkArticleViewOld | |
81.82% |
9 / 11 |
|
66.67% |
2 / 3 |
6.22 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
doWork | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
3 | |||
getCachedWork | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | /** |
3 | * This program is free software; you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation; either version 2 of the License, or |
6 | * (at your option) any later version. |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License along |
14 | * with this program; if not, write to the Free Software Foundation, Inc., |
15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
16 | * http://www.gnu.org/copyleft/gpl.html |
17 | * |
18 | * @file |
19 | */ |
20 | |
21 | namespace MediaWiki\PoolCounter; |
22 | |
23 | use MediaWiki\Logger\Spi as LoggerSpi; |
24 | use MediaWiki\Parser\ParserOutput; |
25 | use MediaWiki\Parser\RevisionOutputCache; |
26 | use MediaWiki\Revision\RevisionRecord; |
27 | use MediaWiki\Revision\RevisionRenderer; |
28 | use MediaWiki\Status\Status; |
29 | use ParserOptions; |
30 | |
31 | /** |
32 | * PoolWorkArticleView for an old revision of a page, using a simple cache. |
33 | * |
34 | * @internal |
35 | */ |
36 | class PoolWorkArticleViewOld extends PoolWorkArticleView { |
37 | /** @var RevisionOutputCache */ |
38 | private $cache; |
39 | |
40 | /** |
41 | * @param string $workKey PoolCounter key. |
42 | * @param RevisionOutputCache $cache The cache to store ParserOutput in. |
43 | * @param RevisionRecord $revision Revision to render |
44 | * @param ParserOptions $parserOptions ParserOptions to use for the parse |
45 | * @param RevisionRenderer $revisionRenderer |
46 | * @param LoggerSpi $loggerSpi |
47 | */ |
48 | public function __construct( |
49 | string $workKey, |
50 | RevisionOutputCache $cache, |
51 | RevisionRecord $revision, |
52 | ParserOptions $parserOptions, |
53 | RevisionRenderer $revisionRenderer, |
54 | LoggerSpi $loggerSpi |
55 | ) { |
56 | parent::__construct( $workKey, $revision, $parserOptions, $revisionRenderer, $loggerSpi ); |
57 | |
58 | $this->cache = $cache; |
59 | |
60 | $this->cacheable = true; |
61 | } |
62 | |
63 | /** |
64 | * @return Status |
65 | */ |
66 | public function doWork() { |
67 | // Reduce effects of race conditions for slow parses (T48014) |
68 | $cacheTime = wfTimestampNow(); |
69 | |
70 | $status = $this->renderRevision(); |
71 | /** @var ParserOutput|null $output */ |
72 | $output = $status->getValue(); |
73 | |
74 | if ( $output && $output->isCacheable() ) { |
75 | $this->cache->save( $output, $this->revision, $this->parserOptions, $cacheTime ); |
76 | } |
77 | |
78 | return $status; |
79 | } |
80 | |
81 | /** |
82 | * @return Status|false |
83 | */ |
84 | public function getCachedWork() { |
85 | $parserOutput = $this->cache->get( $this->revision, $this->parserOptions ); |
86 | |
87 | return $parserOutput ? Status::newGood( $parserOutput ) : false; |
88 | } |
89 | |
90 | } |
91 | |
92 | /** @deprecated class alias since 1.41 */ |
93 | class_alias( PoolWorkArticleViewOld::class, 'PoolWorkArticleViewOld' ); |