Cache our echo and file area stats for page rendering performance reasons
This commit is contained in:
parent
4b309871ec
commit
179233385b
@ -88,22 +88,24 @@ class Domain extends Model
|
||||
|
||||
public function echoarea_stats(): Collection
|
||||
{
|
||||
$dt = Carbon::now()->startOfday();
|
||||
$case = CaseBuilder::whenRaw("datetime >= '?'",$dt->subDay()->format('Y-m-d'))->thenRaw("'day'")
|
||||
->whenRaw("datetime >= '?'",$dt->subDays(7)->format('Y-m-d'))->thenRaw("'week'")
|
||||
->whenRaw("datetime >= '?'",$dt->subMonth()->format('Y-m-d'))->thenRaw("'month'")
|
||||
->elseRaw("'all'");
|
||||
return Cache::remember(md5(sprintf('%d-%s',$this->id,__METHOD__)),self::CACHE_TIME,function() {
|
||||
$dt = Carbon::now()->startOfday();
|
||||
$case = CaseBuilder::whenRaw("datetime >= '?'",$dt->subDay()->format('Y-m-d'))->thenRaw("'day'")
|
||||
->whenRaw("datetime >= '?'",$dt->subDays(7)->format('Y-m-d'))->thenRaw("'week'")
|
||||
->whenRaw("datetime >= '?'",$dt->subMonth()->format('Y-m-d'))->thenRaw("'month'")
|
||||
->elseRaw("'all'");
|
||||
|
||||
return Echoarea::select(['echoareas.id','name','description','active',DB::raw('count(echomails.id) AS count'),DB::raw('min(datetime) as first_message'),DB::raw('max(datetime) as last_message')])
|
||||
->selectRaw($case->toRaw().' AS stats')
|
||||
->join('echomails',['echomails.echoarea_id'=>'echoareas.id'],NULL,NULL,'left outer')
|
||||
->where('domain_id',$this->id)
|
||||
->groupBy('echoareas.id')
|
||||
->groupBy('echoareas.name')
|
||||
->groupBy('stats')
|
||||
->orderBy('echoareas.name')
|
||||
->orderBy('last_message','DESC')
|
||||
->get();
|
||||
return Echoarea::select(['echoareas.id','name','description','active',DB::raw('count(echomails.id) AS count'),DB::raw('min(datetime) as first_message'),DB::raw('max(datetime) as last_message')])
|
||||
->selectRaw($case->toRaw().' AS stats')
|
||||
->join('echomails',['echomails.echoarea_id'=>'echoareas.id'],NULL,NULL,'left outer')
|
||||
->where('domain_id',$this->id)
|
||||
->groupBy('echoareas.id')
|
||||
->groupBy('echoareas.name')
|
||||
->groupBy('stats')
|
||||
->orderBy('echoareas.name')
|
||||
->orderBy('last_message','DESC')
|
||||
->get();
|
||||
});
|
||||
}
|
||||
|
||||
public function echoarea_total_daily(Collection $systems=NULL): Collection
|
||||
@ -126,21 +128,23 @@ class Domain extends Model
|
||||
|
||||
public function filearea_stats()
|
||||
{
|
||||
$dt = Carbon::now()->startOfday();
|
||||
$case = CaseBuilder::whenRaw("datetime >= '?'",$dt->subDays(7)->format('Y-m-d'))->thenRaw("'week'")
|
||||
->whenRaw("datetime >= '?'",$dt->subMonth()->format('Y-m-d'))->thenRaw("'month'")
|
||||
->elseRaw("'all'");
|
||||
return Cache::remember(md5(sprintf('%d-%s',$this->id,__METHOD__)),self::CACHE_TIME,function() {
|
||||
$dt = Carbon::now()->startOfday();
|
||||
$case = CaseBuilder::whenRaw("datetime >= '?'",$dt->subDays(7)->format('Y-m-d'))->thenRaw("'week'")
|
||||
->whenRaw("datetime >= '?'",$dt->subMonth()->format('Y-m-d'))->thenRaw("'month'")
|
||||
->elseRaw("'all'");
|
||||
|
||||
return Filearea::select(['fileareas.id','fileareas.name','description','active',DB::raw('count(files.id) AS count'),DB::raw('min(datetime) as first_file'),DB::raw('max(datetime) as last_file')])
|
||||
->selectRaw($case->toRaw().' AS stats')
|
||||
->join('files',['files.filearea_id'=>'fileareas.id'],NULL,NULL,'left outer')
|
||||
->where('domain_id',$this->id)
|
||||
->groupBy('fileareas.id')
|
||||
->groupBy('fileareas.name')
|
||||
->groupBy('stats')
|
||||
->orderBy('fileareas.name')
|
||||
->orderBy('last_file','DESC')
|
||||
->get();
|
||||
return Filearea::select(['fileareas.id','fileareas.name','description','active',DB::raw('count(files.id) AS count'),DB::raw('min(datetime) as first_file'),DB::raw('max(datetime) as last_file')])
|
||||
->selectRaw($case->toRaw().' AS stats')
|
||||
->join('files',['files.filearea_id'=>'fileareas.id'],NULL,NULL,'left outer')
|
||||
->where('domain_id',$this->id)
|
||||
->groupBy('fileareas.id')
|
||||
->groupBy('fileareas.name')
|
||||
->groupBy('stats')
|
||||
->orderBy('fileareas.name')
|
||||
->orderBy('last_file','DESC')
|
||||
->get();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user