Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 12 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
SuggestionsInfoHandler | |
0.00% |
0 / 12 |
|
0.00% |
0 / 2 |
20 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
run | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | |
3 | namespace GrowthExperiments\Rest\Handler; |
4 | |
5 | use GrowthExperiments\NewcomerTasks\NewcomerTasksInfo; |
6 | use MediaWiki\Rest\SimpleHandler; |
7 | use Wikimedia\ObjectCache\WANObjectCache; |
8 | |
9 | /** |
10 | * Provide information for monitoring suggested edit task pools by type and topic. |
11 | */ |
12 | class SuggestionsInfoHandler extends SimpleHandler { |
13 | /** |
14 | * @var NewcomerTasksInfo |
15 | */ |
16 | private $suggestionsInfo; |
17 | /** |
18 | * @var WANObjectCache |
19 | */ |
20 | private $cache; |
21 | |
22 | /** |
23 | * @param NewcomerTasksInfo $suggestionsInfo |
24 | * @param WANObjectCache $cache |
25 | */ |
26 | public function __construct( |
27 | NewcomerTasksInfo $suggestionsInfo, |
28 | WANObjectCache $cache |
29 | ) { |
30 | $this->suggestionsInfo = $suggestionsInfo; |
31 | $this->cache = $cache; |
32 | } |
33 | |
34 | /** @inheritDoc */ |
35 | public function run() { |
36 | return $this->cache->getWithSetCallback( |
37 | $this->cache->makeKey( 'GrowthExperiments', 'SuggestionsInfoHandler' ), |
38 | $this->cache::TTL_HOUR, |
39 | function ( $oldValue, &$ttl ) { |
40 | $info = $this->suggestionsInfo->getInfo(); |
41 | // Don't cache error responses. |
42 | if ( !$info || isset( $info['error'] ) ) { |
43 | $ttl = $this->cache::TTL_UNCACHEABLE; |
44 | } |
45 | return $info; |
46 | } |
47 | ); |
48 | } |
49 | |
50 | } |