15 private int $flagCounted = 0;
16 private int $flagCleared = 0;
19 private const CACHE_PREFIX =
'sonet_scorer_cache_';
20 private const CACHE_TTL = 10 * 60;
21 private const CACHE_DIR =
'/sonet/counterstate';
23 private const FLAGS = [
30 $this->userId = $userId;
35 return in_array(
$type, self::FLAGS,
true);
45 return count($this->rows);
50 return (
bool) $this->flagCounted;
55 return $this->flagCleared;
60 $cache = Cache::createInstance();
61 $cache->clean($this->getCacheTag(), $this->getCacheDir());
64 private function getCacheDir(): string
66 return self::CACHE_DIR .
'/' . substr(md5($this->userId),2,2) .
'/';
69 private function getCacheTag(): string
76 $limit = Counter::getGlobalLimit();
79 $this->rows = $this->getFlags();
90 ->where(
'USER_ID', $this->userId);
95 $rowsFlag = $this->getFlags();
99 $this->rows =
$query->exec()->fetchAll();
100 if (!is_null($rowsFlag))
102 $this->rows = array_merge($this->rows, $rowsFlag);
106 private function getFlags():
array
109 $cache = Cache::createInstance();
111 if ($cache->initCache(self::CACHE_TTL, $this->getCacheTag(), $this->getCacheDir()))
113 $rows = $cache->getVars();
117 $rows = CounterTable::query()
124 ->where(
'USER_ID', $this->userId)
125 ->whereIn(
'TYPE', self::FLAGS)
132 $taggedCache->StartTagCache($this->getCacheDir());
133 $taggedCache->RegisterTag($this->getCacheTag());
135 $cache->startDataCache();
136 $cache->endDataCache(
$rows);
137 $taggedCache->EndTagCache();
141 foreach (
$rows as $row)
143 switch ($row[
'TYPE'])
145 case CounterDictionary::COUNTER_FLAG_COUNTED:
146 $this->flagCounted = (int) $row[
'VALUE'];
148 case CounterDictionary::COUNTER_FLAG_CLEARED:
149 $this->flagCleared = (int) $row[
'VALUE'];