[], 'model' => [], 'quant' => [], 'engine' => [], 'suite' => [], ]; public function updatedFilters(): void { $this->resetPage(); } public function resetFilters(): void { $this->filters = [ 'gpu' => [], 'model' => [], 'quant' => [], 'engine' => [], 'suite' => [], ]; $this->resetPage(); } public function toggleFilter(string $field, string $value): void { if (! array_key_exists($field, $this->filters)) { return; } $this->filters[$field] = array_values(array_unique( in_array($value, $this->filters[$field], true) ? array_diff($this->filters[$field], [$value]) : array_merge($this->filters[$field], [$value]) )); $this->resetPage(); } public function filterLabel(string $field): string { $count = count($this->filters[$field] ?? []); return $count === 0 ? '' : ' ('.$count.')'; } #[Computed] public function sessions() { $ttl = (int) config('festbench.home_cache_ttl', 300); $user = auth()->user(); // Guest views are shared-cacheable; logged-in views may contain the // user's private bands, so they get a user-scoped key. $cacheKey = 'summary:'.($user?->id ?? 'guest').':'.md5(json_encode([$this->filters, $this->getPage()])); return Cache::remember($cacheKey, $ttl, function () use ($user) { $bands = $this->bandQuery($user)->paginate(10); $runIds = $bands->getCollection()->map(fn ($b) => $b->id)->all(); $suiteRows = $runIds === [] ? collect() : \Illuminate\Support\Facades\DB::table('session_suite_rows') ->whereIn('session_summary_id', $runIds) ->orderBy('sequence') ->get() ->groupBy('session_summary_id'); $bands->getCollection()->transform(fn ($band) => (object) [ 'band' => $band, 'suites' => $suiteRows->get($band->id, collect()), ]); return $bands; }); } private function bandQuery($user) { return \Illuminate\Support\Facades\DB::table('session_summaries') ->where(function ($q) use ($user) { $q->where('visibility', 'public'); if ($user !== null) { $q->orWhere(function ($own) use ($user) { $own->where('visibility', 'private')->where('user_id', $user->id); }); } }) ->when($this->filters['gpu'], fn ($q, array $gpus) => $q->whereIn('gpu', $gpus)) ->when($this->filters['model'], fn ($q, array $models) => $q->whereIn('model_id', $models)) ->when($this->filters['quant'], fn ($q, array $quants) => $q->whereIn('model_quant', $quants)) ->when($this->filters['engine'], fn ($q, array $engines) => $q->whereIn('engine', $engines)) ->when($this->filters['suite'], fn ($q, array $suites) => $q->whereExists(function ($sub) use ($suites) { $sub->select(\Illuminate\Support\Facades\DB::raw(1)) ->from('session_suite_rows') ->whereColumn('session_suite_rows.session_summary_id', 'session_summaries.id') ->whereIn('session_suite_rows.suite', $suites); })) ->orderByDesc('ran_at') ->orderBy('sequence'); } #[Computed] public function gpus(): array { return Cache::remember('summary:gpus', 300, function () { return \Illuminate\Support\Facades\DB::table('session_summaries') ->where('visibility', 'public') ->whereNotNull('gpu') ->distinct()->orderBy('gpu')->pluck('gpu')->all(); }); } #[Computed] public function models(): array { return Cache::remember('summary:models', 300, function () { return \Illuminate\Support\Facades\DB::table('session_summaries') ->where('visibility', 'public') ->whereNotNull('model_id') ->distinct()->orderBy('model_id')->pluck('model_id')->all(); }); } #[Computed] public function quants(): array { return Cache::remember('summary:quants', 300, function () { return \Illuminate\Support\Facades\DB::table('session_summaries') ->where('visibility', 'public') ->whereNotNull('model_quant') ->distinct()->orderBy('model_quant')->pluck('model_quant')->all(); }); } #[Computed] public function engines(): array { return Cache::remember('summary:engines', 300, function () { return \Illuminate\Support\Facades\DB::table('session_summaries') ->where('visibility', 'public') ->whereNotNull('engine') ->distinct()->orderBy('engine')->pluck('engine')->all(); }); } #[Computed] public function suites(): array { return Cache::remember('summary:suites', 300, function () { return \Illuminate\Support\Facades\DB::table('session_suite_rows') ->join('session_summaries', 'session_summaries.id', '=', 'session_suite_rows.session_summary_id') ->where('session_summaries.visibility', 'public') ->distinct()->orderBy('suite')->pluck('suite')->all(); }); } }; ?>