From 23e8522e1a922fca6e3321cc5f44e4b92c11aba5 Mon Sep 17 00:00:00 2001 From: Deon George Date: Sat, 15 Apr 2023 13:34:08 +1000 Subject: [PATCH] Performance enhancements for system view --- app/Http/Controllers/SystemController.php | 2 +- app/Models/System.php | 7 +++++ resources/views/system/view.blade.php | 34 ++++++++++++----------- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/app/Http/Controllers/SystemController.php b/app/Http/Controllers/SystemController.php index 6b4fe24..fcdea18 100644 --- a/app/Http/Controllers/SystemController.php +++ b/app/Http/Controllers/SystemController.php @@ -638,7 +638,7 @@ class SystemController extends Controller public function view(System $o) { - $o->load(['addresses.echomails.echoarea']); + $o->load(['addresses']); return view('system.view') ->with('o',$o); diff --git a/app/Models/System.php b/app/Models/System.php index 725a3e6..6c7a149 100644 --- a/app/Models/System.php +++ b/app/Models/System.php @@ -44,6 +44,13 @@ class System extends Model return $this->hasMany(SystemLog::class); } + public function logs_recent() + { + return $this->hasMany(SystemLog::class) + ->orderby('created_at','DESC') + ->limit(10); + } + /** * Session Passwords for system * diff --git a/resources/views/system/view.blade.php b/resources/views/system/view.blade.php index 3f76c72..07c5c61 100644 --- a/resources/views/system/view.blade.php +++ b/resources/views/system/view.blade.php @@ -39,7 +39,7 @@ @endif Last Seen - {{ $o->logs->count() ? $o->logs->last()->created_at : '-' }} + {{ $o->logs_recent->count() ? $o->logs_recent->last()->created_at : '-' }} @if($o->addresses->count()) @@ -72,29 +72,31 @@ Domain - Echoarea # Last - @foreach($o->addresses->sortBy('zone.domain.name')->groupBy('zone.domain.name') as $net => $children) - @if($children->pluck('echomails')->flatten()->count()) - @foreach($children->pluck('echomails')->flatten()->sortBy('echoarea.name')->groupBy('echoarea.name') as $name => $echomails) - - {{ $net }} - {{ $name }} - {{ ($y=$children->pluck('echomail_from')->flatten()->where('echoarea_id',$x))->count() }} - {{ $y->max('datetime') }} - - @endforeach - @else + @foreach($o->addresses->sortBy('zone.domain.name')->groupBy('zone.domain_id') as $did => $domain_addresses) + @foreach(\App\Models\Echoarea::select([DB::raw('count(echomails.*) as count'),DB::raw('max(echomails.datetime) as most_recent')]) + ->join('echomails',['echomails.echoarea_id'=>'echoareas.id']) + ->join('echomail_seenby',function($join) use ($domain_addresses) { + return $join->on('echomail_seenby.echomail_id','echomails.id') + ->whereIn('echomail_seenby.address_id',$domain_addresses->pluck('id')); + }) + ->get() as $o) - {{ $net }} - No Echoarea Activity + {{ $domain_addresses->first()->zone->domain->name }} + + @if($o->count) + {{ $o->count }} + {{ $o->most_recent }} + @else + No Echoarea Activity + @endif - @endif + @endforeach @endforeach