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";
$durations = Media::select(
DB::raw("{$caseSql} as duration_range"),
DB::raw('COUNT(*) as total')
)
->where('duration', '>', 0) // every positive duration falls into a bucket
// Counts only for buckets that currently have media.
$counts = Media::query()
->select(DB::raw("{$caseSql} as duration_range"), DB::raw('COUNT(*) as total'))
->where('duration', '>', 0)
->where(function ($q) {
$q->where('visibility', 'public')
->orWhere('user_id', auth()->id());
})
->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([
'categories' => $categories,