addMinutes(config('nntmux.cache_expiry_long')), function () use ($type, $activeOnly) { return Genre::getFiltered($type, $activeOnly); }); } /** * Load genres as an associative array (id => lowercase title). * * @return array */ public function loadGenres(string $type): array { $genres = $this->getGenres($type); $genresArray = []; foreach ($genres as $genre) { /** @var Genre $genre */ $genresArray[$genre->id] = strtolower($genre->title); } return $genresArray; } /** * Get a range of genres with pagination. * * @return array */ public function getRange(int $start, int $num, string $type = '', bool $activeOnly = false): Collection // @phpstan-ignore missingType.generics { return Genre::getFiltered($type, $activeOnly) ->skip($start) ->take($num); } /** * Get count of genres. */ public function getCount(string $type = '', bool $activeOnly = false): int { return Genre::getFilteredCount($type, $activeOnly); } /** * Get genre by ID. */ public function getById(int $id): ?Genre { return Genre::find($id); } /** * Update genre disabled status. */ public function update(int $id, int $disabled): int { $this->clearCache(); return Genre::where('id', $id)->update(['disabled' => $disabled]); } /** * Get all disabled genre IDs. */ public function getDisabledIDs(): Collection // @phpstan-ignore missingType.generics { return Cache::remember('disabled_genres', now()->addMinutes(config('nntmux.cache_expiry_long')), function () { return Genre::disabled()->get(['id']); }); } /** * Clear genre-related cache. */ public function clearCache(): void { Cache::forget('disabled_genres'); // Clear other genre caches by pattern if needed } }