Cache our echo and file area stats for page rendering performance reasons
All checks were successful
Create Docker Image / Build Docker Image (x86_64) (push) Successful in 35s
Create Docker Image / Build Docker Image (arm64) (push) Successful in 1m49s
Create Docker Image / Final Docker Image Manifest (push) Successful in 9s

This commit is contained in:
Deon George 2024-10-24 17:00:14 +11:00
parent 4b309871ec
commit 179233385b

View File

@ -88,22 +88,24 @@ class Domain extends Model
public function echoarea_stats(): Collection public function echoarea_stats(): Collection
{ {
$dt = Carbon::now()->startOfday(); return Cache::remember(md5(sprintf('%d-%s',$this->id,__METHOD__)),self::CACHE_TIME,function() {
$case = CaseBuilder::whenRaw("datetime >= '?'",$dt->subDay()->format('Y-m-d'))->thenRaw("'day'") $dt = Carbon::now()->startOfday();
->whenRaw("datetime >= '?'",$dt->subDays(7)->format('Y-m-d'))->thenRaw("'week'") $case = CaseBuilder::whenRaw("datetime >= '?'",$dt->subDay()->format('Y-m-d'))->thenRaw("'day'")
->whenRaw("datetime >= '?'",$dt->subMonth()->format('Y-m-d'))->thenRaw("'month'") ->whenRaw("datetime >= '?'",$dt->subDays(7)->format('Y-m-d'))->thenRaw("'week'")
->elseRaw("'all'"); ->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')]) 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') ->selectRaw($case->toRaw().' AS stats')
->join('echomails',['echomails.echoarea_id'=>'echoareas.id'],NULL,NULL,'left outer') ->join('echomails',['echomails.echoarea_id'=>'echoareas.id'],NULL,NULL,'left outer')
->where('domain_id',$this->id) ->where('domain_id',$this->id)
->groupBy('echoareas.id') ->groupBy('echoareas.id')
->groupBy('echoareas.name') ->groupBy('echoareas.name')
->groupBy('stats') ->groupBy('stats')
->orderBy('echoareas.name') ->orderBy('echoareas.name')
->orderBy('last_message','DESC') ->orderBy('last_message','DESC')
->get(); ->get();
});
} }
public function echoarea_total_daily(Collection $systems=NULL): Collection public function echoarea_total_daily(Collection $systems=NULL): Collection
@ -126,21 +128,23 @@ class Domain extends Model
public function filearea_stats() public function filearea_stats()
{ {
$dt = Carbon::now()->startOfday(); return Cache::remember(md5(sprintf('%d-%s',$this->id,__METHOD__)),self::CACHE_TIME,function() {
$case = CaseBuilder::whenRaw("datetime >= '?'",$dt->subDays(7)->format('Y-m-d'))->thenRaw("'week'") $dt = Carbon::now()->startOfday();
->whenRaw("datetime >= '?'",$dt->subMonth()->format('Y-m-d'))->thenRaw("'month'") $case = CaseBuilder::whenRaw("datetime >= '?'",$dt->subDays(7)->format('Y-m-d'))->thenRaw("'week'")
->elseRaw("'all'"); ->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')]) 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') ->selectRaw($case->toRaw().' AS stats')
->join('files',['files.filearea_id'=>'fileareas.id'],NULL,NULL,'left outer') ->join('files',['files.filearea_id'=>'fileareas.id'],NULL,NULL,'left outer')
->where('domain_id',$this->id) ->where('domain_id',$this->id)
->groupBy('fileareas.id') ->groupBy('fileareas.id')
->groupBy('fileareas.name') ->groupBy('fileareas.name')
->groupBy('stats') ->groupBy('stats')
->orderBy('fileareas.name') ->orderBy('fileareas.name')
->orderBy('last_file','DESC') ->orderBy('last_file','DESC')
->get(); ->get();
});
} }
/** /**