runningUnitTests()) { return $callback(); } return Cache::memo()->remember($key, $seconds, $callback); } public function flush(): void { foreach ($this->keys() as $key) { Cache::memo()->forget($key); } } public function pressReleaseReviewCount(): int { return (int) $this->remember(self::PressReleaseReviewCount, self::StatsTtl, function (): int { return PressRelease::query() ->withoutGlobalScopes() ->where('status', PressReleaseStatus::Review->value) ->count(); }); } public function companiesStatsKey(?string $portal): string { return 'admin.companies.stats.'.($portal ?? 'all'); } public function contactsStatsKey(?string $portal): string { return 'admin.contacts.stats.'.($portal ?? 'all'); } public function categoriesStatsKey(?string $portal): string { return 'admin.categories.stats.'.($portal ?? 'all'); } public function permissionGroupsKey(string $guard): string { return "admin.permissions.groups.{$guard}"; } /** * @return list */ private function keys(): array { $portalKeys = collect([null, ...array_map( static fn (Portal $portal): string => $portal->value, Portal::cases(), )]); return [ self::DashboardStats, self::PressReleaseStats, self::PressReleaseReviewCount, self::PressReleaseCategoryOptions, self::ActiveCategoryOptions, self::RoleOptions, self::UserStats, self::NewsletterStats, self::PresetAreas, self::PresetTypes, $this->permissionGroupsKey('web'), ...$portalKeys->map(fn (?string $portal): string => $this->companiesStatsKey($portal))->all(), ...$portalKeys->map(fn (?string $portal): string => $this->contactsStatsKey($portal))->all(), ...$portalKeys->map(fn (?string $portal): string => $this->categoriesStatsKey($portal))->all(), ]; } }