Performance enhancements for system view

This commit is contained in:
Deon George 2023-04-15 13:34:08 +10:00
parent c5500020ae
commit 23e8522e1a
3 changed files with 26 additions and 17 deletions

View File

@ -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);

View File

@ -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
*

View File

@ -39,7 +39,7 @@
@endif
<tr>
<th>Last Seen</th>
<td>{{ $o->logs->count() ? $o->logs->last()->created_at : '-' }}</td>
<td>{{ $o->logs_recent->count() ? $o->logs_recent->last()->created_at : '-' }}</td>
</tr>
@if($o->addresses->count())
<tr>
@ -72,29 +72,31 @@
<thead>
<tr>
<th>Domain</th>
<th>Echoarea</th>
<th class="text-end">#</th>
<th class="text-end">Last</th>
</tr>
</thead>
<tbody>
@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)
<tr>
<td><a href="{{ url('network',[$children->first()->zone->domain_id]) }}">{{ $net }}</a></td>
<td><a href="{{ url('echoarea/view',[$x=$echomails->first()->echoarea_id]) }}">{{ $name }}</a></td>
<td class="text-end">{{ ($y=$children->pluck('echomail_from')->flatten()->where('echoarea_id',$x))->count() }}</td>
<td class="text-end">{{ $y->max('datetime') }}</td>
</tr>
@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)
<tr>
<td><a href="{{ url('network',[$children->first()->zone->domain_id]) }}">{{ $net }}</a></td>
<td colspan="3">No Echoarea Activity</td>
<td><a href="{{ url('network',[$did]) }}">{{ $domain_addresses->first()->zone->domain->name }}</a></td>
@if($o->count)
<td class="text-end">{{ $o->count }}</td>
<td class="text-end">{{ $o->most_recent }}</td>
@else
<td class="text-end" colspan="2">No Echoarea Activity</td>
@endif
</tr>
@endif
@endforeach
@endforeach
</tbody>
</table>