This commit is contained in:
2026-06-16 14:01:17 +03:30
parent 15dc009ae1
commit 191e5597c0
+14 -6
View File
@@ -339,17 +339,25 @@ public function filters(Request $request)
} }
$caseSql .= "WHEN duration > {$this->durationOtherMin()} THEN '120-' END"; $caseSql .= "WHEN duration > {$this->durationOtherMin()} THEN '120-' END";
$durations = Media::select( // Counts only for buckets that currently have media.
DB::raw("{$caseSql} as duration_range"), $counts = Media::query()
DB::raw('COUNT(*) as total') ->select(DB::raw("{$caseSql} as duration_range"), DB::raw('COUNT(*) as total'))
) ->where('duration', '>', 0)
->where('duration', '>', 0) // every positive duration falls into a bucket
->where(function ($q) { ->where(function ($q) {
$q->where('visibility', 'public') $q->where('visibility', 'public')
->orWhere('user_id', auth()->id()); ->orWhere('user_id', auth()->id());
}) })
->groupBy('duration_range') ->groupBy('duration_range')
->get(); ->pluck('total', 'duration_range');
// Always return every range (the UI needs all of them), with 0 when empty.
$durations = collect(array_keys($this->durationRanges()))
->push('120-')
->map(fn ($key) => [
'duration_range' => $key,
'total' => (int) ($counts[$key] ?? 0),
])
->values();
return response()->json([ return response()->json([
'categories' => $categories, 'categories' => $categories,