More optimisations for users dashboard
This commit is contained in:
parent
20d3776490
commit
3f5668292f
@ -19,8 +19,15 @@ class DomainController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function api_daily_stats(Request $request): Collection
|
public function api_daily_stats(Request $request): Collection
|
||||||
{
|
{
|
||||||
$do = Domain::where('name',$request->name)->firstOrFail();
|
$o = Domain::where('name',$request->name)->firstOrFail();
|
||||||
return $do->daily_area_stats();
|
|
||||||
|
return $o->echoarea_total_daily()
|
||||||
|
->sortBy('date')
|
||||||
|
->groupBy('date')
|
||||||
|
->transform(function($item,$key) { return [
|
||||||
|
'x'=>\Carbon\Carbon::createFromFormat('Y-m-d',$key)->timestamp,
|
||||||
|
'y'=>$item->sum('count')]; } )
|
||||||
|
->values();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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;
|
||||||
@ -69,55 +70,6 @@ class Domain extends Model
|
|||||||
|
|
||||||
/* METHODS */
|
/* METHODS */
|
||||||
|
|
||||||
/**
|
|
||||||
* Get some message area stats for this domain
|
|
||||||
*
|
|
||||||
* @param bool $byarea
|
|
||||||
* @param Collection|NULL $systems
|
|
||||||
* @return Collection
|
|
||||||
*/
|
|
||||||
public function daily_area_stats(bool $byarea=FALSE,Collection $systems=NULL): Collection
|
|
||||||
{
|
|
||||||
if (! $this->echoareas->count())
|
|
||||||
return collect();
|
|
||||||
|
|
||||||
$echostats = Echomail::cacheFor(self::CACHE_TIME)->select([DB::raw('datetime::date as date'),'echoarea_id','echoareas.name',DB::raw('COUNT(*)')])
|
|
||||||
->join('echoareas',['echoareas.id'=>'echomails.echoarea_id'])
|
|
||||||
->join('domains',['domains.id'=>'echoareas.domain_id'])
|
|
||||||
->where('domain_id',$this->id)
|
|
||||||
->when($systems?->count(),function($query) use ($systems) { return $query->whereIn('fftn_id',$systems->pluck('addresses')->flatten()->pluck('id')->toArray()); })
|
|
||||||
->where('datetime','>=',Carbon::now()->subMonths(self::STATS_MONTHS)->startOfMonth())
|
|
||||||
->groupBy(['echoarea_id','echoareas.name','date'])
|
|
||||||
->orderBy('date')
|
|
||||||
->orderBy('echoareas.name')
|
|
||||||
->with(['echoarea'])
|
|
||||||
->get();
|
|
||||||
|
|
||||||
if ($byarea)
|
|
||||||
return $echostats
|
|
||||||
->sortBy('name')
|
|
||||||
->groupBy(['echoarea_id'])
|
|
||||||
->map(function($item,$key) {
|
|
||||||
return [
|
|
||||||
'name' => $item->first()->echoarea->name,
|
|
||||||
'data' => $item->groupby('date')->map(function($item) {
|
|
||||||
return [
|
|
||||||
'x' => Carbon::create($item->first()->date)->timestamp*1000,
|
|
||||||
'y' => $item->sum('count')
|
|
||||||
];
|
|
||||||
})->values(),
|
|
||||||
'dashStyle' => 'ShortDot',
|
|
||||||
'visible'=>(bool)$item->first()->echoarea->show,
|
|
||||||
];
|
|
||||||
})->values();
|
|
||||||
|
|
||||||
else
|
|
||||||
return $echostats
|
|
||||||
->groupBy('date')
|
|
||||||
->map(function($item) { return ['x'=>Carbon::create($item->first()->date)->timestamp*1000,'y'=>$item->sum('count')]; })
|
|
||||||
->values();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function echoarea_stats(): Collection
|
public function echoarea_stats(): Collection
|
||||||
{
|
{
|
||||||
$dt = Carbon::now()->startOfday();
|
$dt = Carbon::now()->startOfday();
|
||||||
@ -139,6 +91,24 @@ class Domain extends Model
|
|||||||
->get();
|
->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function echoarea_total_daily(Collection $systems=NULL): Collection
|
||||||
|
{
|
||||||
|
return Cache::remember(md5(sprintf('%d-%s',$this->id,$systems?->pluck('id')->join(','))),self::CACHE_TIME,function() use ($systems) {
|
||||||
|
return DB::query()
|
||||||
|
->select(['echoareas.name','echoareas.show',DB::raw('COUNT(*) AS count'),DB::raw('datetime::date AS date')])
|
||||||
|
->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.name','echoareas.show','date'])
|
||||||
|
->orderBy('echoareas.name')
|
||||||
|
->orderBy('date')
|
||||||
|
->get();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public function isManaged(): bool
|
public function isManaged(): bool
|
||||||
{
|
{
|
||||||
return our_address()->pluck('zone.domain')->pluck('id')->contains($this->id);
|
return our_address()->pluck('zone.domain')->pluck('id')->contains($this->id);
|
||||||
|
@ -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->echoarea_total_daily()->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->echoarea_total_daily($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,10 @@
|
|||||||
{
|
{
|
||||||
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->echoarea_total_daily()
|
||||||
|
->groupBy('name')
|
||||||
|
->map(function($item,$key) { return ['name'=>$key,'y'=>$item->sum('count'),'drilldown'=>'e-'.$key]; })
|
||||||
|
->values() !!}
|
||||||
},
|
},
|
||||||
@endforeach
|
@endforeach
|
||||||
|
|
||||||
@ -228,7 +231,10 @@
|
|||||||
{
|
{
|
||||||
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->echoarea_total_daily($user->systems)
|
||||||
|
->groupBy('name')
|
||||||
|
->map(function($item,$key) { return ['name'=>$key,'y'=>$item->sum('count'),'drilldown'=>'e-'.$key]; })
|
||||||
|
->values() !!}
|
||||||
},
|
},
|
||||||
@endforeach
|
@endforeach
|
||||||
]
|
]
|
||||||
|
@ -305,7 +305,15 @@
|
|||||||
cursor: 'pointer'
|
cursor: 'pointer'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
series: {!! $o->daily_area_stats('true') !!}
|
series: {!! $o->echoarea_total_daily()
|
||||||
|
->groupBy('name')
|
||||||
|
->transform(function($item,$key) { return [
|
||||||
|
'name'=>$key,
|
||||||
|
'dashStyle'=>'ShortDot',
|
||||||
|
'visible'=>$item->first()->show,
|
||||||
|
'data'=>$item->map(function($item) { return ['x'=>\Carbon\Carbon::createFromFormat('Y-m-d',$item->date)->timestamp,'y'=>$item->count]; })
|
||||||
|
]; })
|
||||||
|
->values() !!}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
@append
|
@append
|
Loading…
Reference in New Issue
Block a user