1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Wikibase\EntityStore\Cache; |
4
|
|
|
|
5
|
|
|
use Ask\Language\Description\Description; |
6
|
|
|
use Ask\Language\Option\QueryOptions; |
7
|
|
|
use OutOfBoundsException; |
8
|
|
|
use Wikibase\EntityStore\ItemIdForQueryLookup; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Internal class |
12
|
|
|
* |
13
|
|
|
* @licence GPLv2+ |
14
|
|
|
* @author Thomas Pellissier Tanon |
15
|
|
|
*/ |
16
|
|
|
class CachedItemIdForQueryLookup implements ItemIdForQueryLookup { |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var ItemIdForQueryLookup |
20
|
|
|
*/ |
21
|
|
|
private $itemIdForQueryLookup; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var EntityIdForQueryCache |
25
|
|
|
*/ |
26
|
|
|
private $entityIdForQueryCache; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param ItemIdForQueryLookup $itemIdForQueryLookup |
30
|
|
|
* @param EntityIdForQueryCache $entityIdForQueryCache |
31
|
|
|
*/ |
32
|
3 |
|
public function __construct( |
33
|
|
|
ItemIdForQueryLookup $itemIdForQueryLookup, |
34
|
|
|
EntityIdForQueryCache $entityIdForQueryCache |
35
|
|
|
) { |
36
|
3 |
|
$this->itemIdForQueryLookup = $itemIdForQueryLookup; |
37
|
3 |
|
$this->entityIdForQueryCache = $entityIdForQueryCache; |
38
|
3 |
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @see ItemIdForQueryLookup::getItemIdsForQuery |
42
|
|
|
*/ |
43
|
3 |
|
public function getItemIdsForQuery( Description $description, QueryOptions $queryOptions = null ) { |
44
|
|
|
try { |
45
|
3 |
|
return $this->entityIdForQueryCache->fetch( $description, $queryOptions, 'item' ); |
46
|
2 |
|
} catch( OutOfBoundsException $e ) { |
47
|
2 |
|
$itemIds = $this->itemIdForQueryLookup->getItemIdsForQuery( $description, $queryOptions ); |
48
|
2 |
|
$this->entityIdForQueryCache->save( $description, $queryOptions, 'item', $itemIds ); |
49
|
2 |
|
return $itemIds; |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|