Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
16 / 16 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
BagOStuffStatsStore | |
100.00% |
16 / 16 |
|
100.00% |
5 / 5 |
7 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
makeKey | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
incr | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
2 | |||
delete | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
query | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace Wikimedia\WRStats; |
4 | |
5 | use Wikimedia\ObjectCache\BagOStuff; |
6 | |
7 | /** |
8 | * An adaptor allowing WRStats to store data in MediaWiki's BagOStuff |
9 | * |
10 | * @newable |
11 | * @since 1.39 |
12 | */ |
13 | class BagOStuffStatsStore implements StatsStore { |
14 | /** @var BagOStuff */ |
15 | private $cache; |
16 | |
17 | /** |
18 | * @param BagOStuff $cache |
19 | */ |
20 | public function __construct( BagOStuff $cache ) { |
21 | $this->cache = $cache; |
22 | } |
23 | |
24 | /** |
25 | * @inheritDoc |
26 | * @suppress PhanParamTooFewUnpack |
27 | */ |
28 | public function makeKey( $prefix, $internals, $entity ) { |
29 | if ( $entity->isGlobal() ) { |
30 | return $this->cache->makeGlobalKey( |
31 | ...$prefix, ...$internals, ...$entity->getComponents() ); |
32 | } else { |
33 | return $this->cache->makeKey( |
34 | ...$prefix, ...$internals, ...$entity->getComponents() ); |
35 | } |
36 | } |
37 | |
38 | public function incr( array $values, $ttl ) { |
39 | foreach ( $values as $key => $value ) { |
40 | $this->cache->incrWithInit( |
41 | $key, |
42 | $ttl, |
43 | $value, |
44 | $value, |
45 | BagOStuff::WRITE_BACKGROUND |
46 | ); |
47 | } |
48 | } |
49 | |
50 | public function delete( array $keys ) { |
51 | $this->cache->deleteMulti( $keys, BagOStuff::WRITE_BACKGROUND ); |
52 | } |
53 | |
54 | public function query( array $keys ) { |
55 | return $this->cache->getMulti( $keys ); |
56 | } |
57 | } |