From 69b7f1fcb93b97c65c3c12c131b12d55116f2d69 Mon Sep 17 00:00:00 2001 From: Roardom Date: Sun, 22 Sep 2024 08:00:08 +0000 Subject: [PATCH] add: client torrent size sum to profile page This query's execution time is increased from 10 ms to ~550 ms for power users with a few thousand torrents, or ~30 ms for average users with a few dozen torrents. Is the increased page load time worth its usefulness? --- app/Http/Controllers/User/UserController.php | 8 +++++++- resources/views/user/profile/show.blade.php | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/User/UserController.php b/app/Http/Controllers/User/UserController.php index 17627f1a03..62b943ed19 100644 --- a/app/Http/Controllers/User/UserController.php +++ b/app/Http/Controllers/User/UserController.php @@ -93,8 +93,14 @@ public function show(Request $request, User $user): \Illuminate\Contracts\View\F // 'boughtDownload' => BonTransactions::where('sender_id', '=', $user->id)->where([['name', 'like', '%Download%']])->sum('cost'), 'invitedBy' => Invite::where('accepted_by', '=', $user->id)->first(), 'clients' => $user->peers() + ->join('torrents', 'torrents.id', '=', 'peers.torrent_id') ->select('agent', 'port') - ->selectRaw('INET6_NTOA(ip) as ip, MIN(created_at) as created_at, MAX(updated_at) as updated_at, COUNT(*) as num_peers, MAX(connectable) as connectable') + ->selectRaw('INET6_NTOA(peers.ip) as ip') + ->selectRaw('MIN(peers.created_at) as created_at') + ->selectRaw('MAX(peers.updated_at) as updated_at') + ->selectRaw('SUM(torrents.size) as size') + ->selectRaw('COUNT(*) as num_peers') + ->selectRaw('MAX(peers.connectable) as connectable') ->groupBy(['ip', 'port', 'agent']) ->where('active', '=', true) ->get(), diff --git a/resources/views/user/profile/show.blade.php b/resources/views/user/profile/show.blade.php index 0a48d8d4bf..d4a88d606c 100644 --- a/resources/views/user/profile/show.blade.php +++ b/resources/views/user/profile/show.blade.php @@ -256,6 +256,7 @@ class="user-search__avatar" {{ __('torrent.started') }} {{ __('torrent.last-update') }} {{ __('torrent.peers') }} + {{ __('torrent.size') }} @if (\config('announce.connectable_check') === true) Connectable @endif @@ -300,6 +301,9 @@ class="user-search__avatar" {{ $client->num_peers }} + + {{ App\Helpers\StringHelper::formatBytes($client->size) }} + @if (\config('announce.connectable_check') == true) @php $connectable = false;