More optimisations for users dashboard
This commit is contained in:
parent
20d3776490
commit
4e43736dcc
@ -8,6 +8,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use Illuminate\Support\Facades\Cache;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
use App\Casts\CompressedString;
|
use App\Casts\CompressedString;
|
||||||
@ -154,4 +155,21 @@ class Domain extends Model
|
|||||||
{
|
{
|
||||||
return our_address($this)->count() > 0;
|
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();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
@ -186,7 +186,7 @@
|
|||||||
@foreach($dl as $do)
|
@foreach($dl as $do)
|
||||||
{
|
{
|
||||||
name: '{{ $do->name }}',
|
name: '{{ $do->name }}',
|
||||||
y: {{ $do->daily_area_stats()->sum('y') }},
|
y: {{ $do->total_echomail()->sum('count') }},
|
||||||
drilldown: 'n-{{ $do->name }}',
|
drilldown: 'n-{{ $do->name }}',
|
||||||
},
|
},
|
||||||
@endforeach
|
@endforeach
|
||||||
@ -200,7 +200,7 @@
|
|||||||
@foreach($dl as $do)
|
@foreach($dl as $do)
|
||||||
{
|
{
|
||||||
name: '{{ $do->name }}',
|
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 }}',
|
drilldown: 'ny-{{ $do->name }}',
|
||||||
color: Highcharts.color(Highcharts.getOptions().colors[{{$loop->index}}]).brighten(-0.2).get()
|
color: Highcharts.color(Highcharts.getOptions().colors[{{$loop->index}}]).brighten(-0.2).get()
|
||||||
},
|
},
|
||||||
@ -220,7 +220,7 @@
|
|||||||
{
|
{
|
||||||
name: '{{ $do->name }}',
|
name: '{{ $do->name }}',
|
||||||
id: 'n-{{ $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
|
@endforeach
|
||||||
|
|
||||||
@ -228,7 +228,7 @@
|
|||||||
{
|
{
|
||||||
name: '{{ $do->name }}',
|
name: '{{ $do->name }}',
|
||||||
id: 'ny-{{ $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
|
@endforeach
|
||||||
]
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user