From 23e551374a84a2d91de0944d38134a7c58330466 Mon Sep 17 00:00:00 2001 From: Paul Couture Date: Sun, 17 Dec 2023 23:22:54 -0600 Subject: [PATCH] fix: caching the leaderboard --- site/app/Http/Controllers/PageController.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/site/app/Http/Controllers/PageController.php b/site/app/Http/Controllers/PageController.php index e0a4aa0..c29624d 100644 --- a/site/app/Http/Controllers/PageController.php +++ b/site/app/Http/Controllers/PageController.php @@ -100,8 +100,9 @@ private function numberFormatPrecision($number, $precision = 2, $separator = '.' } private function leaderboardTwelveMonths() { - $endDate = now()->endOfDay()->subYear()->format('Y-m-d'); - $leaderboard = DB::table('episodes') + $leaderboard = cache()->remember('leaderboardTwelveMonths', 30, function() { + $endDate = now()->endOfDay()->subYear()->format('Y-m-d'); + $leaderboard = DB::table('episodes') ->join('artworks', 'artworks.id', '=', 'episodes.artwork_id') ->join('artists', 'artists.id', '=', 'artworks.artist_id') ->select([ @@ -115,7 +116,9 @@ private function leaderboardTwelveMonths() { ->orderByDesc('artworkCount') ->limit(10) ->get(); - $leaderboard = $this->addArtistModelToLeaderboard($leaderboard); + $leaderboard = $this->addArtistModelToLeaderboard($leaderboard); + return $leaderboard; + }); return $leaderboard; }