diff --git a/app/Actions/Tabulation/AllJudgesCount.php b/app/Actions/Tabulation/AllJudgesCount.php index 9ee70b7..aa76b98 100644 --- a/app/Actions/Tabulation/AllJudgesCount.php +++ b/app/Actions/Tabulation/AllJudgesCount.php @@ -7,17 +7,20 @@ namespace App\Actions\Tabulation; use App\Exceptions\TabulationException; use App\Models\Entry; use App\Services\AuditionService; +use App\Services\EntryService; use Illuminate\Support\Facades\Cache; class AllJudgesCount implements CalculateEntryScore { protected CalculateScoreSheetTotal $calculator; protected AuditionService $auditionService; + protected EntryService $entryService; - public function __construct(CalculateScoreSheetTotal $calculator, AuditionService $auditionService) + public function __construct(CalculateScoreSheetTotal $calculator, AuditionService $auditionService, EntryService $entryService) { $this->calculator = $calculator; $this->auditionService = $auditionService; + $this->entryService = $entryService; } public function calculate(string $mode, Entry $entry): array @@ -60,7 +63,7 @@ class AllJudgesCount implements CalculateEntryScore throw new TabulationException('Mode must be seating or advancement'); } - if (! $entry->exists()) { + if (! $this->entryService->entryExists($entry)) { throw new TabulationException('Invalid entry specified'); } } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index ca321fa..3bd6621 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -71,6 +71,6 @@ class AppServiceProvider extends ServiceProvider User::observe(UserObserver::class); SeatingLimit::observe(SeatingLimitObserver::class); - //Model::preventLazyLoading(! app()->isProduction()); + Model::preventLazyLoading(! app()->isProduction()); } } diff --git a/app/Services/AuditionService.php b/app/Services/AuditionService.php index d542ef5..d38648c 100644 --- a/app/Services/AuditionService.php +++ b/app/Services/AuditionService.php @@ -42,21 +42,65 @@ class AuditionService 'seating' => 'for_seating', 'advancement' => 'for_advance', }; - + $audition->load('scoringGuide.subscores'); return $audition->scoringGuide->subscores->where($modeColumn, true)->sortBy($sortColumn); }); } - public function getJudges(Audition $audition) + public function getSubscoresNEW(Audition $audition, $mode = 'seating', $sort = 'tiebreak') + { + $this->validateMode($mode); + $this->validateSort($sort); + $cacheKey = 'auditionSubscores-'.$mode.'-'.$sort; + $assignments = Cache::remember($cacheKey, 60, function () use ($audition, $mode, $sort) { + $this->validateAudition($audition); + $sortColumn = match ($sort) { + 'tiebreak' => 'tiebreak_order', + 'display' => 'display_order', + }; + $modeColumn = match ($mode) { + 'seating' => 'for_seating', + 'advancement' => 'for_advance', + }; + $allAuditions = Audition::with(['scoringGuide.subscores' => function ($query) use ($modeColumn, $sortColumn) { + $query->where($modeColumn, 1)->orderBy($sortColumn); + }])->get(); + $return = []; + foreach ( $allAuditions as $audition) { + $return[$audition->id] = $audition->scoringGuide->subscores; + } + return $return; + }); + return $assignments[$audition->id]; + } + + public function getJudgesOLD(Audition $audition) { $cacheKey = 'auditionJudges-'.$audition->id; return Cache::remember($cacheKey, 10, function () use ($audition) { $this->validateAudition($audition); + return $audition->judges; }); } + public function getJudges(Audition $audition) + { + $cacheKey = 'auditionJudgeAssignments'; + $assignments = Cache::remember($cacheKey, 60, function () { + $allAuditions = Audition::with('judges')->get(); + $return = []; + foreach ($allAuditions as $audition) { + $return[$audition->id] = $audition->judges; + } + + return $return; + }); + + return $assignments[$audition->id]; + } + protected function validateAudition($audition) { if (! $audition->exists()) { diff --git a/tests/Feature/Actions/CalculateEntryScore/AllJudgesCountTest.php b/tests/Feature/Actions/CalculateEntryScore/AllJudgesCountTest.php index efb7e99..17c1dbd 100644 --- a/tests/Feature/Actions/CalculateEntryScore/AllJudgesCountTest.php +++ b/tests/Feature/Actions/CalculateEntryScore/AllJudgesCountTest.php @@ -130,7 +130,6 @@ it('correctly calculates scores for advancement', function () { 1004 => 85, 1005 => 95, ]; - #$calculator = new AllJudgesCount(); $calculator = App::make(AllJudgesCount::class); enterScore($judge1, $entry, $scores); enterScore($judge2, $entry, $scores2);