More optimisations for users dashboard
All checks were successful
Create Docker Image / Build Docker Image (x86_64) (push) Successful in 39s
Create Docker Image / Build Docker Image (arm64) (push) Successful in 1m40s
Create Docker Image / Final Docker Image Manifest (push) Successful in 10s

This commit is contained in:
Deon George 2024-04-20 22:03:47 +10:00
parent 20d3776490
commit 4e43736dcc
2 changed files with 22 additions and 4 deletions

View File

@ -8,6 +8,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use App\Casts\CompressedString;
@ -154,4 +155,21 @@ class Domain extends Model
{
return our_address($this)->count() > 0;
}
public function total_echomail(Collection $systems=NULL): Collection
{
return Cache::remember(sprintf('%d-%s',$this->id,$systems?->pluck('id')->join(',')),self::CACHE_TIME,function() use ($systems) {
return DB::query()
->select(['echoareas.name',DB::raw('count(*) as count')])
->from($this->getTable())
->join('echoareas',['echoareas.domain_id'=>'domains.id'])
->join('echomails',['echomails.echoarea_id'=>'echoareas.id'])
->where('domains.id',$this->id)
->where('echomails.datetime','>=',Carbon::now()->subMonths(self::STATS_MONTHS)->startOfMonth())
->when($systems?->count(),function($query) use ($systems) { return $query->whereIn('echomails.fftn_id',$systems->pluck('addresses')->flatten()->pluck('id')); })
->groupBy(['echoareas.id'])
->orderBy('echoareas.name')
->get();
});
}
}

View File

@ -186,7 +186,7 @@
@foreach($dl as $do)
{
name: '{{ $do->name }}',
y: {{ $do->daily_area_stats()->sum('y') }},
y: {{ $do->total_echomail()->sum('count') }},
drilldown: 'n-{{ $do->name }}',
},
@endforeach
@ -200,7 +200,7 @@
@foreach($dl as $do)
{
name: '{{ $do->name }}',
y: {{ $do->daily_area_stats(FALSE,$user->systems)->sum('y') }},
y: {{ $do->total_echomail($user->systems)->sum('count') }},
drilldown: 'ny-{{ $do->name }}',
color: Highcharts.color(Highcharts.getOptions().colors[{{$loop->index}}]).brighten(-0.2).get()
},
@ -220,7 +220,7 @@
{
name: '{{ $do->name }}',
id: 'n-{{ $do->name }}',
data: {!! $do->daily_area_stats(TRUE)->sortBy('name')->map(function($item) { return ['name'=>$item['name'],'y'=>$item['data']->sum('y'),'drilldown'=>'e-'.$item['name']]; })->values() !!}
data: {!! $do->total_echomail()->map(function($item) { return ['name'=>$item->name,'y'=>$item->count,'drilldown'=>'e-'.$item->name]; })->values() !!}
},
@endforeach
@ -228,7 +228,7 @@
{
name: '{{ $do->name }}',
id: 'ny-{{ $do->name }}',
data: {!! $do->daily_area_stats(TRUE,$user->systems)->sortBy('name')->map(function($item) { return ['name'=>$item['name'],'y'=>$item['data']->sum('y'),'drilldown'=>'ey-'.$item['name']]; })->values() !!}
data: {!! $do->total_echomail($user->systems)->map(function($item) { return ['name'=>$item->name,'y'=>$item->count,'drilldown'=>'ey-'.$item->name]; })->values() !!}
},
@endforeach
]