From bac41969a5d581bc4484ccb6b31e1333ec8cd416 Mon Sep 17 00:00:00 2001 From: Deon George Date: Sun, 14 Apr 2024 00:47:08 +1000 Subject: [PATCH] Optimise queries for rendering the users dashboard page --- app/Http/Controllers/UserController.php | 9 -- app/Models/System.php | 1 + app/Models/User.php | 1 - resources/views/dashboard.blade.php | 112 ++++++++++++++---------- routes/web.php | 2 +- 5 files changed, 68 insertions(+), 57 deletions(-) diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index a18537c..748ff8b 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -36,15 +36,6 @@ class UserController extends Controller ->with('o',$o); } - public function dashboard() - { - $user = Auth::user(); - $user->load('systems.addresses.zone.domain.echoareas'); - - return view('dashboard') - ->with('user',$user); - } - public function link(Request $request) { if ($request->post()) { diff --git a/app/Models/System.php b/app/Models/System.php index abcf296..717e115 100644 --- a/app/Models/System.php +++ b/app/Models/System.php @@ -71,6 +71,7 @@ class System extends Model ->where('addresses.active',TRUE) ->where('zones.active',TRUE) ->where('domains.active',TRUE) + ->orderBy('domains.name') ->FTNorder() ->orderBy('role','ASC'); } diff --git a/app/Models/User.php b/app/Models/User.php index abd6b94..1aabe28 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -102,7 +102,6 @@ class User extends Authenticatable implements MustVerifyEmail */ public function isZC(): bool { - $this->load(['systems.addresses']); return $this->zc()->count() > 0; } diff --git a/resources/views/dashboard.blade.php b/resources/views/dashboard.blade.php index 6a5d248..8c000ac 100644 --- a/resources/views/dashboard.blade.php +++ b/resources/views/dashboard.blade.php @@ -3,57 +3,77 @@ Dashboard @endsection +@php($user->load(['systems.akas.zone.domain.echoareas','systems.akas.echoareas'])) + @section('content')

{{ $user->name }}

-
- @if($user->systems->count()) -
+ @if($user->systems->count()) +
+
-
-
-
- - - - - - @foreach ($user->systems as $o) - - - - - @endforeach - -
System Addresses
{{ $o->name }}{!! $o->akas->pluck('ftn')->join('
') !!}
-
-
+
+ + + + + -
-
-
System Addresses
- - - - - @foreach ($user->systems as $o) - - - - - @endforeach - -
Available Echos
{{ $o->name }}{!! $o->addresses->pluck('zone.domain.echoareas')->flatten()->pluck('name')->unique()->sort()->join(', ') !!}
-
-
+ @foreach ($user->systems->sortBy('name') as $o) + + {{ $o->name }} + + {{ $o->akas->count() }} AKAs configured

+ @if ($o->akas->count()) + @foreach ($o->akas as $ao) + {{ $ao->ftn }} ({{ $ao->security ?: '-' }})
+ @endforeach + @else + - + @endif + + + @endforeach + +
- @else -

You are not linked to any BBS systems. Start here to link to your first.

- @endif -
+
+ +
+
+

Active and Available Echos

+ + + @foreach (($dl=$user + ->systems + ->pluck('akas')->flatten() + ->pluck('zone.domain') + ->unique() + ->filter(function($item) { return $item->active && $item->public && $item->isManaged(); }) + ->sortBy('name')) as $o) + + + + + @endforeach + +
+ {{ $o->name }} ({{ $sec=$user->systems->pluck('akas')->flatten()->filter(function($item) use ($o) { return $item->zone->domain_id === $o->id; })->max('security') ?? '-' }})

+ {{ ($sub=$user->systems->pluck('akas')->flatten()->pluck('echoareas')->flatten()->filter(function($item) use ($o) { return $item->domain_id === $o->id; }))->count() }} Subscribed +
+ @foreach ($o->echoareas->sortBy('name') as $eo) + {{ $eo->name }} + @endforeach +
+
+
+ + @else +

You are not linked to any BBS systems. Start here to link to your first.

+ @endif @endsection @section('page-css') @@ -162,7 +182,7 @@ name: 'Networks', colorByPoint: true, data: [ - @foreach(($xx=$user->systems->pluck('addresses')->flatten()->pluck('zone.domain')->unique(function($item) { return $item->name; })->sortBy('name')) as $do) + @foreach($dl as $do) { name: '{{ $do->name }}', y: {{ $do->daily_area_stats()->sum('y') }}, @@ -176,7 +196,7 @@ colorByPoint: true, pointPlacement: 0.1, data: [ - @foreach($xx as $do) + @foreach($dl as $do) { name: '{{ $do->name }}', y: {{ $do->daily_area_stats(FALSE,$user->systems)->sum('y') }}, @@ -195,7 +215,7 @@ } }, series: [ - @foreach($xx as $do) + @foreach($dl as $do) { name: '{{ $do->name }}', id: 'n-{{ $do->name }}', @@ -203,7 +223,7 @@ }, @endforeach - @foreach($xx as $do) + @foreach($dl as $do) { name: '{{ $do->name }}', id: 'ny-{{ $do->name }}', diff --git a/routes/web.php b/routes/web.php index 97143f4..52ac462 100644 --- a/routes/web.php +++ b/routes/web.php @@ -52,7 +52,7 @@ Route::get('system/view/{o}',[SystemController::class,'view']) Route::get('search',[HomeController::class,'search']); Route::middleware(['auth','verified','activeuser'])->group(function () { - Route::get('dashboard',[UserController::class,'dashboard']); + Route::view('dashboard','dashboard'); /* DOMAIN PATHS */ Route::view('domain','domain.home');