From 72db2b35b50df16ce9df169da53fb95517e6d806 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Mon, 7 Oct 2019 19:48:58 -0600 Subject: [PATCH] Update AdminController, improve dashboard caching --- app/Http/Controllers/AdminController.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php index 6fcd1a412..80d096fb9 100644 --- a/app/Http/Controllers/AdminController.php +++ b/app/Http/Controllers/AdminController.php @@ -45,20 +45,21 @@ class AdminController extends Controller public function home() { - $data = Cache::remember('admin:dashboard:home:data', now()->addMinutes(15), function() { - $day = config('database.default') == 'pgsql' ? 'DATE_PART(\'day\',' : 'day('; + $day = config('database.default') == 'pgsql' ? 'DATE_PART(\'day\',' : 'day('; + + $recent = Cache::remember('admin:dashboard:home:data:15min', now()->addMinutes(15), function() use ($day) { return [ 'contact' => [ 'count' => PrettyNumber::convert(Contact::whereNull('read_at')->count()), - 'graph' => Contact::selectRaw('count(*) as count, '.$day.'created_at) as day')->whereNull('read_at')->whereBetween('created_at',[now()->subDays(14), now()])->groupBy('day')->orderBy('day')->pluck('count') + 'graph' => Contact::selectRaw('count(*) as count, '.$day.'created_at) as d')->groupBy('d')->whereNull('read_at')->whereBetween('created_at',[now()->subDays(14), now()])->orderBy('d')->pluck('count') ], 'failedjobs' => [ 'count' => PrettyNumber::convert(FailedJob::where('failed_at', '>=', \Carbon\Carbon::now()->subDay())->count()), - 'graph' => FailedJob::selectRaw('count(*) as count, '.$day.'failed_at) as d')->groupBy('d')->whereBetween('failed_at',[now()->subDays(24), now()])->orderBy('d')->pluck('count') + 'graph' => FailedJob::selectRaw('count(*) as count, '.$day.'failed_at) as d')->groupBy('d')->whereBetween('failed_at',[now()->subDays(14), now()])->orderBy('d')->pluck('count') ], 'reports' => [ 'count' => PrettyNumber::convert(Report::whereNull('admin_seen')->count()), - 'graph' => Report::selectRaw('count(*) as count, '.$day.'created_at) as day')->whereBetween('created_at',[now()->subDays(14), now()])->groupBy('day')->orderBy('day')->pluck('count') + 'graph' => Report::selectRaw('count(*) as count, '.$day.'created_at) as d')->whereBetween('created_at',[now()->subDays(14), now()])->groupBy('d')->orderBy('d')->pluck('count') ], 'statuses' => [ 'count' => PrettyNumber::convert(Status::whereNull('in_reply_to_id')->whereNull('reblog_of_id')->count()), @@ -80,6 +81,11 @@ class AdminController extends Controller 'count' => PrettyNumber::convert(Profile::count()), 'graph' => Profile::selectRaw('count(*) as count, '.$day.'created_at) as day')->whereBetween('created_at',[now()->subDays(14), now()])->groupBy('day')->orderBy('day')->pluck('count') ], + ]; + }); + + $longer = Cache::remember('admin:dashboard:home:data:24hr', now()->addHours(24), function() use ($day) { + return [ 'users' => [ 'count' => PrettyNumber::convert(User::count()), 'graph' => User::selectRaw('count(*) as count, '.$day.'created_at) as day')->whereBetween('created_at',[now()->subDays(14), now()])->groupBy('day')->orderBy('day')->pluck('count') @@ -98,6 +104,8 @@ class AdminController extends Controller ] ]; }); + + $data = array_merge($recent, $longer); return view('admin.home', compact('data')); }