1 |
protected function select($query): array |
2 |
{ |
3 |
static $ch; |
4 |
if ($ch === null) { |
5 |
$ch = connection::factory(connection::CONNECTION_FULLSTREAM); |
6 |
$ch->getConnection()->setConnectTimeOut(3600); |
7 |
$ch->getConnection()->setTimeout(3600); |
8 |
$ch->getConnection()->settings()->set('max_memory_usage', 40000000000); |
9 |
$ch->getConnection()->settings()->set('max_execution_time', 3600*1); |
10 |
$ch->getConnection()->settings()->set('readonly', 2); |
11 |
$ch->getConnection()->setReadOnlyUser(false); |
12 |
$ch->getConnection()->settings()->readonly(false); |
13 |
} |
14 |
$cacheKey = "astats_{$this->period}_" .md5(json_encode($query)). '.json'; |
15 |
if(file_exists($cacheKey)) { |
16 |
self::log()->addDebug("query cached {$cacheKey}"); |
17 |
return json_decode(file_get_contents($cacheKey), true); |
18 |
} |
19 |
print($query . PHP_EOL); |
20 |
$q = new Query($query); |
21 |
$q->setFormat('JSON'); |
22 |
$cursor = $ch->select($q); |
23 |
self::log()->addInfo("Cursor count: {$cursor->count()}"); |
24 |
if(empty($cursor->count())) { |
25 |
if($cursor->isError()) { |
26 |
var_dump($cursor->error(), $cursor->isError()); |
27 |
throw new mpcmfException('CH query failed'); |
28 |
} |
29 |
} |
30 |
file_put_contents($cacheKey, json_encode($cursor->rows(), 448)); |
31 |
return $cursor->rows(); |
32 |
} |
Комментарии