diff --git a/app/Http/Controllers/RequestController.php b/app/Http/Controllers/RequestController.php index 87de7b94f6..14d53b6d9b 100644 --- a/app/Http/Controllers/RequestController.php +++ b/app/Http/Controllers/RequestController.php @@ -35,6 +35,7 @@ use App\Repositories\RequestFacetedRepository; use Carbon\Carbon; use Illuminate\Http\Request; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Str; use MarcReichel\IGDBLaravel\Models\Game; @@ -63,7 +64,7 @@ public function __construct(RequestFacetedRepository $faceted, ChatRepository $c } /** - * Displays Torrent List View. + * Displays Requests List View. * * @param \Illuminate\Http\Request $request * @@ -72,12 +73,17 @@ public function __construct(RequestFacetedRepository $faceted, ChatRepository $c public function requests(Request $request) { $user = $request->user(); - $num_req = TorrentRequest::count(); - $num_fil = TorrentRequest::whereNotNull('filled_by')->count(); - $num_unfil = TorrentRequest::whereNull('filled_by')->count(); - $total_bounty = TorrentRequest::all()->sum('bounty'); - $claimed_bounty = TorrentRequest::whereNotNull('filled_by')->sum('bounty'); - $unclaimed_bounty = TorrentRequest::whereNull('filled_by')->sum('bounty'); + + $requests = DB::table('requests') + ->selectRaw('count(*) as total') + ->selectRaw('count(case when filled_by != null then 1 end) as filled') + ->selectRaw('count(case when filled_by = null then 1 end) as unfilled') + ->first(); + $bounties = DB::table('requests') + ->selectRaw('coalesce(sum(bounty), 0) as total') + ->selectRaw('coalesce(sum(case when filled_by != null then 1 end), 0) as claimed') + ->selectRaw('coalesce(sum(case when filled_by = null then 1 end), 0) as unclaimed') + ->first(); $torrentRequests = TorrentRequest::with(['user', 'category', 'type'])->paginate(25); $repository = $this->faceted; @@ -86,12 +92,8 @@ public function requests(Request $request) 'torrentRequests' => $torrentRequests, 'repository' => $repository, 'user' => $user, - 'num_req' => $num_req, - 'num_fil' => $num_fil, - 'num_unfil' => $num_unfil, - 'total_bounty' => $total_bounty, - 'claimed_bounty' => $claimed_bounty, - 'unclaimed_bounty' => $unclaimed_bounty, + 'requests' => $requests, + 'bounties' => $bounties, ]); } diff --git a/app/Http/Controllers/Staff/HomeController.php b/app/Http/Controllers/Staff/HomeController.php index 721fcb0675..39c9a97f80 100644 --- a/app/Http/Controllers/Staff/HomeController.php +++ b/app/Http/Controllers/Staff/HomeController.php @@ -15,13 +15,9 @@ use App\Helpers\SystemInformation; use App\Http\Controllers\Controller; -use App\Models\Application; use App\Models\Group; -use App\Models\Peer; -use App\Models\Report; -use App\Models\Torrent; -use App\Models\User; use Illuminate\Http\Request; +use Illuminate\Support\Facades\DB; use Spatie\SslCertificate\SslCertificate; class HomeController extends Controller @@ -40,22 +36,36 @@ public function index(Request $request) // User Info $banned_group = cache()->rememberForever('banned_group', fn () => Group::where('slug', '=', 'banned')->pluck('id')); $validating_group = cache()->rememberForever('validating_group', fn () => Group::where('slug', '=', 'validating')->pluck('id')); - $num_user = User::count(); - $banned = User::where('group_id', '=', $banned_group[0])->count(); - $validating = User::where('group_id', '=', $validating_group[0])->count(); + $users = DB::table('users') + ->selectRaw('count(*) as total') + ->selectRaw("count(case when group_id = $banned_group[0] then 1 end) as banned") + ->selectRaw("count(case when group_id = $validating_group[0] then 1 end) as validating") + ->first(); // Torrent Info - $num_torrent = Torrent::count(); - $pending = Torrent::pending()->count(); - $rejected = Torrent::rejected()->count(); + $torrents = DB::table('torrents') + ->selectRaw('count(*) as total') + ->selectRaw('count(case when status = 0 then 1 end) as pending') + ->selectRaw('count(case when status = 2 then 1 end) as rejected') + ->selectRaw('count(case when status = 3 then 1 end) as postponed') + ->first(); // Peers Info - $peers = Peer::count(); - $seeders = Peer::where('seeder', '=', 1)->count(); - $leechers = Peer::where('seeder', '=', 0)->count(); + $peers = DB::table('peers') + ->selectRaw('count(*) as total') + ->selectRaw('count(case when seeder = 0 then 1 end) as leechers') + ->selectRaw('count(case when seeder = 1 then 1 end) as seeders') + ->first(); // Reports Info - $reports_count = Report::where('solved', '=', 0)->count(); + $reports = DB::table('reports') + ->selectRaw('count(case when solved = 0 then 1 end) as unsolved') + ->first(); + + // Pending Applications Count + $apps = DB::table('applications') + ->selectRaw('count(case when status = 0 then 1 end) as pending') + ->first(); // SSL Info try { @@ -75,20 +85,12 @@ public function index(Request $request) // Directory Permissions $file_permissions = $sys->directoryPermissions(); - // Pending Applications Count - $app_count = Application::pending()->count(); - return view('Staff.dashboard.index', [ - 'num_user' => $num_user, - 'banned' => $banned, - 'validating' => $validating, - 'num_torrent' => $num_torrent, - 'pending' => $pending, - 'rejected' => $rejected, + 'users' => $users, + 'torrents' => $torrents, 'peers' => $peers, - 'seeders' => $seeders, - 'leechers' => $leechers, - 'reports_count' => $reports_count, + 'reports' => $reports, + 'apps' => $apps, 'certificate' => $certificate, 'uptime' => $uptime, 'ram' => $ram, @@ -96,7 +98,6 @@ public function index(Request $request) 'avg' => $avg, 'basic' => $basic, 'file_permissions' => $file_permissions, - 'app_count' => $app_count, ]); } } diff --git a/resources/views/Staff/dashboard/index.blade.php b/resources/views/Staff/dashboard/index.blade.php index 2a7ab18aa1..b97ea62b89 100644 --- a/resources/views/Staff/dashboard/index.blade.php +++ b/resources/views/Staff/dashboard/index.blade.php @@ -88,10 +88,10 @@

Torrents

- Total: {{ $num_torrent }} + Total: {{ $torrents->total }}
- Pending: {{ $pending }} - Rejected: {{ $rejected }} + Pending: {{ $torrents->pending }} + Rejected: {{ $torrents->rejected }}
@@ -99,10 +99,10 @@

Peers

- Total: {{ $peers }} + Total: {{ $peers->total }}
- Seeders: {{ $seeders }} - Leechers: {{ $leechers }} + Seeders: {{ $peers->seeders }} + Leechers: {{ $peers->leechers }}
@@ -110,10 +110,10 @@

Users

- Total: {{ $num_user }} + Total: {{ $users->total }}
- Validating: {{ $validating }} - Banned: {{ $banned }} + Validating: {{ $users->validating }} + Banned: {{ $users->banned }}
diff --git a/resources/views/partials/dashboardmenu.blade.php b/resources/views/partials/dashboardmenu.blade.php index 1c40e5baee..9592bebae9 100644 --- a/resources/views/partials/dashboardmenu.blade.php +++ b/resources/views/partials/dashboardmenu.blade.php @@ -64,7 +64,7 @@
  • @lang('staff.applications') - {{ $app_count }} + {{ $apps->pending }}
  • @if (auth()->user()->group->is_admin) @@ -201,7 +201,7 @@
  • @lang('staff.reports-log') - {{ $reports_count }} + {{ $reports->unsolved }}
  • diff --git a/resources/views/requests/requests.blade.php b/resources/views/requests/requests.blade.php index cd38778343..1e1cfb5183 100644 --- a/resources/views/requests/requests.blade.php +++ b/resources/views/requests/requests.blade.php @@ -187,12 +187,12 @@ class="form-horizontal form-condensed form-torrent-search form-bordered">
    - @lang('request.requests'): {{ $num_req }} | - @lang('request.filled'): {{ $num_fil }} | - @lang('request.unfilled'): {{ $num_unfil }} | - @lang('request.total-bounty'): {{ $total_bounty }} @lang('bon.bon') | - @lang('request.bounty-claimed'): {{ $claimed_bounty }} @lang('bon.bon') | - @lang('request.bounty-unclaimed'): {{ $unclaimed_bounty }} @lang('bon.bon') + @lang('request.requests'): {{ $requests->total }} | + @lang('request.filled'): {{ $requests->filled }} | + @lang('request.unfilled'): {{ $requests->unfilled }} | + @lang('request.total-bounty'): {{ $bounties->total }} @lang('bon.bon') | + @lang('request.bounty-claimed'): {{ $bounties->claimed }} @lang('bon.bon') | + @lang('request.bounty-unclaimed'): {{ $bounties->unclaimed }} @lang('bon.bon')