optimize: torrents list

Eager load the bookmarks and fl tokens
This commit is contained in:
Roardom
2023-02-15 06:01:51 -06:00
parent 4b9603eca3
commit dc4a161fc0
9 changed files with 63 additions and 68 deletions
+4 -1
View File
@@ -84,7 +84,10 @@ class TorrentController extends Controller
{
$user = $request->user();
$torrent = Torrent::withAnyStatus()->with(['user', 'comments', 'category', 'type', 'resolution', 'subtitles', 'playlists'])->findOrFail($id);
$torrent = Torrent::withAnyStatus()
->with(['user', 'comments', 'category', 'type', 'resolution', 'subtitles', 'playlists'])
->withExists(['bookmarks' => fn ($query) => $query->where('user_id', '=', $user->id)])
->findOrFail($id);
$freeleechToken = cache()->get('freeleech_token:'.$user->id.':'.$torrent->id);
$personalFreeleech = cache()->get('personal_freeleech:'.$user->id);
$totalTips = BonTransactions::where('torrent_id', '=', $id)->sum('cost');