feat(playlist): enhance public playlist index with hero stats and loading optimizations
Add a redesigned hero section to the public playlist page displaying community-generated totals for playlists and episodes, plus new string translations (English, German, French). Eager-load user, limited episode previews, and first gallery image to reduce N+1 queries. Cache aggregate statistics for 10 minutes to improve performance on high-traffic pages.
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace App\Livewire;
|
||||
|
||||
use App\Models\Playlist;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Livewire\Attributes\Url;
|
||||
use Livewire\Component;
|
||||
use Livewire\WithPagination;
|
||||
@@ -54,11 +55,30 @@ class Playlists extends Component
|
||||
->withCount('episodes')
|
||||
->having('episodes_count', '>', 1)
|
||||
->when($this->search != '', fn ($query) => $query->where('name', 'like', '%'.$this->search.'%'))
|
||||
->with([
|
||||
'user',
|
||||
'episodes' => fn ($query) => $query->orderBy('position')->limit(4),
|
||||
'episodes.episode.gallery' => fn ($query) => $query->limit(1),
|
||||
])
|
||||
->orderBy($orderby, $orderdirection)
|
||||
->paginate($this->pagination);
|
||||
|
||||
$stats = Cache::remember('publicPlaylistStats', 600, function () {
|
||||
$playlists = Playlist::where('is_private', 0)
|
||||
->withCount('episodes')
|
||||
->having('episodes_count', '>', 1)
|
||||
->get();
|
||||
|
||||
return [
|
||||
'playlists' => $playlists->count(),
|
||||
'episodes' => $playlists->sum('episodes_count'),
|
||||
];
|
||||
});
|
||||
|
||||
return view('livewire.playlists', [
|
||||
'playlists' => $playlists,
|
||||
'totalPlaylists' => $stats['playlists'],
|
||||
'totalEpisodes' => $stats['episodes'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user