activeCount !== null) { return $this->activeCount; } $cache = Cache::createInstance(); $cacheId = "active-count-" . $this->iblockType . "-" . $this->iblockCode; if ($cache->initCache(self::CACHE_TTL, $cacheId, self::CACHE_DIR)) { return $this->activeCount = (int)$cache->getVars()["count"]; } $cache->startDataCache(); $taggedCache = Application::getInstance()->getTaggedCache(); $taggedCache->startTagCache(self::CACHE_DIR); try { $iblockId = $this->getIblockId(); $count = ElementTable::getCount([ "=IBLOCK_ID" => $iblockId, "=ACTIVE" => "Y", ]); $taggedCache->registerTag("iblock_id_" . $iblockId); } catch (\Throwable $e) { $taggedCache->abortTagCache(); $cache->abortDataCache(); throw $e; } $taggedCache->endTagCache(); $cache->endDataCache(["count" => $count]); return $this->activeCount = $count; } private function getIblockId(): int { if (!Loader::includeModule("iblock")) { throw new SystemException("Module iblock is not installed"); } $iblock = IblockTable::getRow([ "select" => ["ID"], "filter" => ["=IBLOCK_TYPE_ID" => $this->iblockType, "=CODE" => $this->iblockCode], ]); if ($iblock === null) { throw new SystemException("Iblock " . $this->iblockType . "/" . $this->iblockCode . " not found"); } return (int)$iblock["ID"]; } }