1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
cacherate.php
См. документацию.
1
<?php
2
3
namespace
Bitrix\Perfmon\Controller
;
4
5
use \Bitrix\Main\Error;
6
use \Bitrix\Main\IO\Path;
7
use
Bitrix\Perfmon\Model\CacheHitrateTable
;
8
9
class
Cacherate
extends
\Bitrix\Main\Engine\Controller
10
{
11
public
function
recountStatAction
(
int
$offset = 0,
int
$processed = 0): ?
array
12
{
13
if
($this->
getCurrentUser
()->isAdmin())
14
{
15
$connection
=
\Bitrix\Main\Application::getConnection
();
16
17
if
($offset === 0)
18
{
19
$totalCount
= (int)
$connection
->query(
'SELECT COUNT(1) AS CNT FROM b_perf_cache'
)->fetch()[
'CNT'
];
20
\Bitrix\Main\Config\Option::set
(
'perfmon'
,
'cacheTotalItems'
,
$totalCount
);
21
\Bitrix\Main\Config\Option::set
(
'perfmon'
,
'cacheRateTotal'
, 0);
22
23
$connection
->truncateTable(
CacheHitrateTable::getTableName
());
24
}
25
else
26
{
27
$totalCount
= (int) \
Bitrix
\
Main
\Config\Option::get(
'perfmon'
,
'cacheTotalItems'
, 0);
28
}
29
30
if
(
$totalCount
=== 0)
31
{
32
return
[
33
'TOTAL_ITEMS'
=> 0,
34
'PROCESSED_ITEMS'
=> 0,
35
'STATUS'
=>
'COMPLETED'
,
36
'SUMMARY'
=>
'NOTHING'
,
37
];
38
}
39
40
$lastId
= 0;
41
$cacheRate = [];
42
$hitrateRes =
$connection
->query(
'
43
SELECT
44
cache.ID,
45
cache.BASE_DIR,
46
cache.INIT_DIR,
47
cache.FILE_NAME,
48
cache.MODULE_NAME,
49
cache.OP_MODE,
50
cache.CACHE_SIZE
51
FROM b_perf_cache cache
52
WHERE
53
cache.ID > '
. $offset .
'
54
ORDER BY cache.ID ASC
55
LIMIT 500
56
'
);
57
58
$count
= 0;
59
while
($cache = $hitrateRes->fetch())
60
{
61
$lastId
= (int) $cache[
'ID'
];
62
$count
++;
63
if
($cache[
'FILE_NAME'
] ===
''
)
64
{
65
continue
;
66
}
67
$hash
= md5(Path::normalize($cache[
'BASE_DIR'
] . $cache[
'INIT_DIR'
] . $cache[
'FILE_NAME'
]));
68
if
(isset($cacheRate[
$hash
]))
69
{
70
if
($cache[
'OP_MODE'
] ===
'R'
)
71
{
72
$cacheRate[
$hash
][
'READ_COUNT'
] += 1;
73
}
74
elseif
($cache[
'OP_MODE'
] ===
'W'
)
75
{
76
$cacheRate[
$hash
][
'WRITE_COUNT'
] += 1;
77
}
78
elseif
($cache[
'OP_MODE'
] ===
'C'
)
79
{
80
$cacheRate[
$hash
][
'CLEAN_COUNT'
] += 1;
81
}
82
83
$cacheRate[
$hash
][
'CACHE_SIZE'
] = (int) $cacheRate[
'CACHE_SIZE'
] > $cache[
'CACHE_SIZE'
] ? $cacheRate[
'CACHE_SIZE'
] : $cache[
'CACHE_SIZE'
];
84
}
85
else
86
{
87
$cacheRate[
$hash
] = [
88
'HASH'
=>
$hash
,
89
'MODULE_ID'
=> $cache[
'MODULE_NAME'
],
90
'BASE_DIR'
=> $cache[
'BASE_DIR'
],
91
'INIT_DIR'
=> $cache[
'INIT_DIR'
],
92
'FILE_NAME'
=> $cache[
'FILE_NAME'
],
93
'READ_COUNT'
=> $cache[
'OP_MODE'
] ===
'R'
? 1 : 0,
94
'WRITE_COUNT'
=> $cache[
'OP_MODE'
] ===
'W'
? 1 : 0,
95
'CLEAN_COUNT'
=> $cache[
'OP_MODE'
] ===
'C'
? 1 : 0,
96
'CACHE_SIZE'
=> (int) $cache[
'CACHE_SIZE'
],
97
];
98
}
99
}
100
101
if
(!empty($cacheRate))
102
{
103
$toUpdateRate = [];
104
$existedRates =
CacheHitrateTable::query
()
105
->setSelect([
'ID'
,
'HASH'
,
'READ_COUNT'
,
'WRITE_COUNT'
,
'CLEAN_COUNT'
,
'CACHE_SIZE'
])
106
->whereIn(
'HASH'
, array_keys($cacheRate))
107
->exec()
108
->fetchCollection()
109
;
110
111
foreach
($existedRates as $eRate)
112
{
113
$hash
= $eRate->getHash();
114
$eRate->set(
'READ_COUNT'
, (
int
) $eRate->get(
'READ_COUNT'
) + $cacheRate[
$hash
][
'READ_COUNT'
]);
115
$eRate->set(
'WRITE_COUNT'
, (
int
) $eRate->get(
'WRITE_COUNT'
) + $cacheRate[
$hash
][
'WRITE_COUNT'
]);
116
$eRate->set(
'CLEAN_COUNT'
, (
int
) $eRate->get(
'CLEAN_COUNT'
) + $cacheRate[
$hash
][
'CLEAN_COUNT'
]);
117
if
($cacheRate[
$hash
][
'CACHE_SIZE'
] > $eRate->get(
'CACHE_SIZE'
))
118
{
119
$eRate->set(
'CACHE_SIZE'
, $cacheRate[
$hash
][
'CACHE_SIZE'
]);
120
}
121
$toUpdateRate[
$hash
] =
true
;
122
}
123
124
$toAddRate = array_diff_key($cacheRate, $toUpdateRate);
125
unset($cacheRate);
126
127
foreach
($toAddRate as $rate)
128
{
129
$newRate = new \Bitrix\Perfmon\Model\EO_CacheHitrate;
130
foreach
($rate as $fieldName => $fieldValue)
131
{
132
$newRate->set($fieldName, $fieldValue);
133
}
134
$existedRates->add($newRate);
135
}
136
137
$saveResult = $existedRates->save(
true
);
138
139
if
(!$saveResult->isSuccess())
140
{
141
$this->
addError
(
new
Error
(
'Couldn\'t add/update rows'
));
142
143
return
null
;
144
}
145
146
return
[
147
'TOTAL_ITEMS'
=>
$totalCount
,
148
'PROCESSED_ITEMS'
=> $processed +
$count
,
149
'STATUS'
=>
'PROGRESS'
,
150
'SUMMARY'
=>
''
,
151
'LAST_ID'
=>
$lastId
,
152
];
153
}
154
155
return
[
156
'TOTAL_ITEMS'
=>
$totalCount
,
157
'PROCESSED_ITEMS'
=>
$totalCount
,
158
'STATUS'
=>
'COMPLETED'
,
159
'SUMMARY'
=>
''
,
160
];
161
}
162
163
$this->
addError
(
new
Error
(
'Who are you?'
));
164
165
return
null
;
166
}
167
168
public
function
countRateAction
(
int
$offset = 0,
int
$processed = 0):
array
|null
169
{
170
if
($this->
getCurrentUser
()->isAdmin())
171
{
172
if
($offset === 0)
173
{
174
$totalCount
= (int)
CacheHitrateTable::getCount
([
'>READ_COUNT'
=> 0]);
175
\Bitrix\Main\Config\Option::set
(
'perfmon'
,
'rateTotalItems'
,
$totalCount
);
176
}
177
else
178
{
179
$totalCount
= (int) \
Bitrix
\
Main
\Config\Option::get(
'perfmon'
,
'rateTotalItems'
, 0);
180
}
181
182
if
(
$totalCount
=== 0)
183
{
184
return
[
185
'TOTAL_ITEMS'
=> 0,
186
'PROCESSED_ITEMS'
=> 0,
187
'STATUS'
=>
'COMPLETED'
,
188
'SUMMARY'
=>
'NOTHING'
,
189
];
190
}
191
192
$lastId
= $offset;
193
$count
= 0;
194
$rateData =
CacheHitrateTable::query
()
195
->setSelect([
'ID'
,
'READ_COUNT'
,
'WRITE_COUNT'
,
'CLEAN_COUNT'
])
196
->where(
'ID'
,
'>'
, $offset)
197
->where(
'READ_COUNT'
,
'>'
, 0)
198
->setOrder([
'ID'
=>
'ASC'
])
199
->setLimit(200)
200
->fetchCollection()
201
;
202
203
if
(!$rateData->isEmpty())
204
{
205
foreach
($rateData as $rate)
206
{
207
$lastId
= $rate->getId();
208
$count
++;
209
210
$rate->setRate(round($rate->get(
'READ_COUNT'
) / ($rate->get(
'READ_COUNT'
) + $rate->get(
'WRITE_COUNT'
) + $rate->get(
'CLEAN_COUNT'
)) * 100), 1);
211
}
212
213
$rateData->save(
true
);
214
215
return
[
216
'TOTAL_ITEMS'
=>
$totalCount
,
217
'PROCESSED_ITEMS'
=> $processed +
$count
,
218
'STATUS'
=>
'PROGRESS'
,
219
'SUMMARY'
=>
''
,
220
'LAST_ID'
=>
$lastId
,
221
];
222
}
223
224
return
[
225
'TOTAL_ITEMS'
=>
$totalCount
,
226
'PROCESSED_ITEMS'
=>
$totalCount
,
227
'STATUS'
=>
'COMPLETED'
,
228
'SUMMARY'
=>
''
,
229
];
230
}
231
232
$this->
addError
(
new
Error
(
'Who are you?'
));
233
234
return
null
;
235
}
236
237
public
function
countTotalRateAction
()
238
{
239
if
($this->
getCurrentUser
()->isAdmin())
240
{
241
$totalRate =
CacheHitrateTable::query
()
242
->addSelect(\
Bitrix
\
Main
\Entity\Query::expr()->avg(
'RATE'
),
'TOTALRATE'
)
243
->fetch()
244
;
245
if
($totalRate)
246
{
247
$totalRate = round($totalRate[
'TOTALRATE'
], 1);
248
}
249
else
250
{
251
$totalRate = 0;
252
}
253
254
\Bitrix\Main\Config\Option::set
(
'perfmon'
,
'cacheRateTotal'
, $totalRate);
255
\Bitrix\Main\Config\Option::set
(
'perfmon'
,
'cacheRateDate'
, (
new
\DateTime())->getTimestamp());
256
257
return
[
258
'TOTAL_ITEMS'
=> 1,
259
'PROCESSED_ITEMS'
=> 1,
260
'STATUS'
=>
'COMPLETED'
,
261
'SUMMARY'
=>
''
,
262
'TOTAL_RATE'
=> $totalRate,
263
];
264
}
265
}
266
}
$connection
$connection
Определения
actionsdefinitions.php:38
$count
$count
Определения
admin_tab.php:4
$hash
$hash
Определения
ajax_redirector.php:8
Bitrix\Main\Application\getConnection
static getConnection($name="")
Определения
application.php:638
Bitrix\Main\Config\Option\set
static set($moduleId, $name, $value="", $siteId="")
Определения
option.php:261
Bitrix\Main\Engine\Controller\addError
addError(Error $error)
Определения
controller.php:1070
Bitrix\Main\Engine\Controller\getCurrentUser
getCurrentUser()
Определения
controller.php:268
Bitrix\Main\Error
Определения
error.php:15
Bitrix\Main\ORM\Data\DataManager\query
static query()
Определения
datamanager.php:549
Bitrix\Main\ORM\Data\DataManager\getCount
static getCount($filter=array(), array $cache=array())
Определения
datamanager.php:516
Bitrix\Perfmon\Controller\Cacherate
Определения
cacherate.php:10
Bitrix\Perfmon\Controller\Cacherate\countRateAction
countRateAction(int $offset=0, int $processed=0)
Определения
cacherate.php:168
Bitrix\Perfmon\Controller\Cacherate\countTotalRateAction
countTotalRateAction()
Определения
cacherate.php:237
Bitrix\Perfmon\Controller\Cacherate\recountStatAction
recountStatAction(int $offset=0, int $processed=0)
Определения
cacherate.php:11
Bitrix\Perfmon\Model\CacheHitrateTable
Определения
cachehitratetable.php:47
Bitrix\Perfmon\Model\CacheHitrateTable\getTableName
static getTableName()
Определения
cachehitratetable.php:53
$lastId
if(!\Bitrix\Main\Loader::includeModule('clouds')) $lastId
Определения
sync.php:68
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
Bitrix\Main\Controller
Определения
agreement.php:2
Bitrix\Main
Bitrix\Perfmon\Controller
Определения
cacherate.php:3
Bitrix
elseif
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения
prolog_main_admin.php:393
$totalCount
$totalCount
Определения
subscription_card_product.php:51
bitrix
modules
perfmon
lib
controller
cacherate.php
Создано системой
1.14.0