Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
8 / 8 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| ParserCacheFilter | |
100.00% |
8 / 8 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| shouldCache | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * @license GPL-2.0-or-later |
| 4 | * @file |
| 5 | * @ingroup Cache Parser |
| 6 | */ |
| 7 | |
| 8 | namespace MediaWiki\Parser; |
| 9 | |
| 10 | use MediaWiki\Page\PageRecord; |
| 11 | |
| 12 | /** |
| 13 | * Filter that decides whether a ParserOutput object should be stored in the |
| 14 | * ParserCache or not. Can be used tweak tradeoffs between storage space and |
| 15 | * response latency. |
| 16 | * |
| 17 | * @since 1.42 |
| 18 | */ |
| 19 | class ParserCacheFilter { |
| 20 | |
| 21 | /** |
| 22 | * @see MainConfigSchema::ParserCacheFilterConfig |
| 23 | */ |
| 24 | private array $config; |
| 25 | |
| 26 | /** |
| 27 | * @param array[] $config See MainConfigSchema::ParserCacheFilterConfig. |
| 28 | */ |
| 29 | public function __construct( array $config ) { |
| 30 | $this->config = $config; |
| 31 | } |
| 32 | |
| 33 | public function shouldCache( |
| 34 | ParserOutput $output, |
| 35 | PageRecord $page, |
| 36 | ParserOptions $options |
| 37 | ): bool { |
| 38 | $ns = $page->getNamespace(); |
| 39 | $cpuMin = $this->config[ $ns ]['minCpuTime'] |
| 40 | ?? ( $this->config['default']['minCpuTime'] ?? 0 ); |
| 41 | |
| 42 | $cpuTime = $output->getTimeProfile( 'cpu' ); |
| 43 | |
| 44 | if ( $cpuTime !== null && $cpuTime < $cpuMin ) { |
| 45 | return false; |
| 46 | } |
| 47 | |
| 48 | return true; |
| 49 | } |
| 50 | |
| 51 | } |