-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueryCacheValidator.class.php
More file actions
78 lines (74 loc) · 2.5 KB
/
QueryCacheValidator.class.php
File metadata and controls
78 lines (74 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
/**
* Класс валидатора запроса
*
* Реализует хук десериализации ParserOutput (т.к. самого хука в ядре нет).
*
* Хук необходим для проверки валидации содержимого страницы:
* если произошли изменения в страницах, которые попадают под запрос,
* то кэш страницы инвалидируется и при парсинге страницы происходит выборка нового контента
*
*/
class TPLQueryCacheValidator
{
/**
* @var ParserOutput
*/
protected $mOutput;
/**
* @var array
*/
protected $options;
public function __construct($mOutput, $options)
{
$this->mOutput = $mOutput;
$this->options = $options;
}
/**
* Достаём запрос из кэша страницы и сравниваем результаты в кэше с результатами запроса
*/
public function __wakeup()
{
$dbr = wfGetDB(DB_SLAVE);
$res = $dbr->select(
$this->options['tables'],
$this->options['select'],
$this->options['where'],
__METHOD__,
$this->options['opt'],
$this->options['joins']
);
$result = true;
foreach ($res as $row)
{
$title = Title::newFromRow($row);
if (!is_object($title))
{
continue;
}
// проверяем, что в кэше такие же страницы, что и в выборке
if ($title->userCan('read'))
{
if (!isset($this->options['results'][$title->getArticleID()]) ||
($title->getLatestRevID() != $this->options['results'][$title->getArticleID()]))
{
// Новая страница или ревизия...
$result = false;
}
}
elseif (isset($this->options['results'][$title->getArticleID()]))
{
// изменились права к странице и теперь юзер её не увидит
$result = false;
}
if (!$result)
{
break;
}
}
if (!$result)
{
$this->mOutput->mCacheExpiry = 0;
}
}
}