From d9041b329e245c056e269ba488c74fac5b361fd8 Mon Sep 17 00:00:00 2001 From: Matt Young Date: Sun, 23 Jun 2024 23:52:05 -0500 Subject: [PATCH] Add published auditions cache to AuditionCacheService --- .../Controllers/Tabulation/TabulationController.php | 9 ++++++++- app/Services/AuditionCacheService.php | 12 ++++++++++++ resources/views/test.blade.php | 3 +-- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/Tabulation/TabulationController.php b/app/Http/Controllers/Tabulation/TabulationController.php index e157deb..d5afb88 100644 --- a/app/Http/Controllers/Tabulation/TabulationController.php +++ b/app/Http/Controllers/Tabulation/TabulationController.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers\Tabulation; use App\Http\Controllers\Controller; use App\Models\Audition; use App\Models\Seat; +use App\Services\AuditionCacheService; use App\Services\DoublerService; use App\Services\SeatingService; use App\Services\TabulationService; @@ -20,11 +21,17 @@ class TabulationController extends Controller protected $seatingService; - public function __construct(TabulationService $tabulationService, DoublerService $doublerService, SeatingService $seatingService) + protected $auditionCacheService; + + public function __construct(TabulationService $tabulationService, + DoublerService $doublerService, + SeatingService $seatingService, + AuditionCacheService $auditionCacheService) { $this->tabulationService = $tabulationService; $this->doublerService = $doublerService; $this->seatingService = $seatingService; + $this->auditionCacheService = $auditionCacheService; } public function status() diff --git a/app/Services/AuditionCacheService.php b/app/Services/AuditionCacheService.php index 5e9374d..9d19938 100644 --- a/app/Services/AuditionCacheService.php +++ b/app/Services/AuditionCacheService.php @@ -58,4 +58,16 @@ class AuditionCacheService } Cache::forget($this->cacheKey); } + + public function publishedAuditions() + { + $cacheKey = 'publishedAuditions'; + + return Cache::remember( + $cacheKey, + now()->addHour(), + function () { + return Audition::orderBy('score_order')->get()->filter(fn ($audition) => $audition->hasFlag('seats_published')); + }); + } } diff --git a/resources/views/test.blade.php b/resources/views/test.blade.php index f42f2f0..8b45c6d 100644 --- a/resources/views/test.blade.php +++ b/resources/views/test.blade.php @@ -16,8 +16,7 @@ Test Page @php - $audition = Audition::find(2); - $audition->removeFlag('testFlag'); + dump($auditionService->publishedAuditions()); @endphp