diff --git a/app/Actions/Tabulation/PublishSeats.php b/app/Actions/Tabulation/PublishSeats.php index 7c37b23..8b2928f 100644 --- a/app/Actions/Tabulation/PublishSeats.php +++ b/app/Actions/Tabulation/PublishSeats.php @@ -27,5 +27,6 @@ class PublishSeats } $audition->addFlag('seats_published'); Cache::forget('resultsSeatList'); + Cache::forget('publicResultsPage'); } } diff --git a/app/Actions/Tabulation/UnpublishSeats.php b/app/Actions/Tabulation/UnpublishSeats.php index e00cbbc..f3e867b 100644 --- a/app/Actions/Tabulation/UnpublishSeats.php +++ b/app/Actions/Tabulation/UnpublishSeats.php @@ -16,6 +16,7 @@ class UnpublishSeats { $audition->removeFlag('seats_published'); Cache::forget('resultsSeatList'); + Cache::forget('publicResultsPage'); Seat::where('audition_id', $audition->id)->delete(); } } diff --git a/app/Http/Controllers/ResultsPage.php b/app/Http/Controllers/ResultsPage.php index 31d1bdb..ba2ddf0 100644 --- a/app/Http/Controllers/ResultsPage.php +++ b/app/Http/Controllers/ResultsPage.php @@ -10,6 +10,7 @@ use App\Models\Seat; use App\Services\AuditionService; use Illuminate\Http\Request; use Illuminate\Support\Facades\Cache; +use Illuminate\Support\Facades\View; use function auditionSetting; @@ -27,6 +28,12 @@ class ResultsPage extends Controller */ public function __invoke(Request $request) { + $cacheKey = 'publicResultsPage'; + + if (Cache::has($cacheKey)) { + return response(Cache::get($cacheKey)); + } + $publishedAdvancementAuditions = []; $resultsAdvancementList = []; $publishedAuditions = Audition::seatsPublished() @@ -34,48 +41,59 @@ class ResultsPage extends Controller ->with('seats.entry.student') ->with('event.ensembles') ->orderBy('score_order')->get(); - $resultsSeatList = Cache::rememberForever('resultsSeatList', function () use ($publishedAuditions) { - $seatList = []; - // Load the $seatList in the form of $seatlist[audition_id] is an array of seats for that audition - // each $seatList[audition_id][] will contain a string with ensemble and seat number and the student object filling it - foreach ($publishedAuditions as $audition) { - $seats = $audition->seats->groupBy('ensemble_id'); - $ensembles = $audition->event->ensembles; - foreach ($ensembles as $ensemble) { - if (! $seats->has($ensemble->id)) { // If there are no students seated in this ensemble, skip it - continue; - } - foreach ($seats[$ensemble->id] as $seat) { - /** @var Seat $seat */ - $seatList[$audition->id][] = [ - 'seat' => $ensemble->name.' '.$seat->seat, - 'student' => $seat->entry->student, - ]; + $resultsSeatList = Cache::rememberForever('resultsSeatList', + function () use ($publishedAuditions) { + $seatList = []; + // Load the $seatList in the form of $seatlist[audition_id] is an array of seats for that audition + // each $seatList[audition_id][] will contain a string with ensemble and seat number and the student object filling it + foreach ($publishedAuditions as $audition) { + $seats = $audition->seats->groupBy('ensemble_id'); + $ensembles = $audition->event->ensembles; + foreach ($ensembles as $ensemble) { + if (! $seats->has($ensemble->id)) { // If there are no students seated in this ensemble, skip it + continue; + } + foreach ($seats[$ensemble->id] as $seat) { + /** @var Seat $seat */ + $seatList[$audition->id][] = [ + 'seat' => $ensemble->name.' '.$seat->seat, + 'student' => $seat->entry->student, + ]; + } } } - } - return $seatList; - }); + return $seatList; + }); if (auditionSetting('advanceTo')) { $publishedAdvancementAuditions = Audition::advancementPublished()->orderBy('score_order')->get(); - $resultsAdvancementList = Cache::rememberForever('resultsAdvancementList', - function () { - // get entries with a related flag of will_advance - $advancingEntries = Entry::forAdvancement()->with('student.school') - ->whereHas('flags', function ($query) { - $query->where('flag_name', EntryFlags::WILL_ADVANCE); - }) - ->get(); - $advancingEntries = $advancingEntries->sortBy(function ($entry) { - return $entry->student->full_name(true); - }); - return $advancingEntries->groupBy('audition_id'); - }); + // get entries with a related flag of will_advance + $advancingEntries = Entry::forAdvancement()->with('student.school') + ->whereHas('flags', function ($query) { + $query->where('flag_name', EntryFlags::WILL_ADVANCE); + }) + ->get(); + $advancingEntries = $advancingEntries->sortBy(function ($entry) { + return $entry->student->full_name(true); + }); + + $resultsAdvancementList = $advancingEntries->groupBy('audition_id'); + } - return view('results.index', compact('publishedAuditions', 'resultsSeatList', 'publishedAdvancementAuditions', 'resultsAdvancementList')); + $content = View::make('results.index', + compact('publishedAuditions', 'resultsSeatList', 'publishedAdvancementAuditions', + 'resultsAdvancementList'))->render(); + + Cache::forever($cacheKey, $content); + + return response($content); + } + + private function generateResultsPage() + { + } } diff --git a/app/Http/Controllers/Tabulation/AdvancementController.php b/app/Http/Controllers/Tabulation/AdvancementController.php index d759c79..a596d59 100644 --- a/app/Http/Controllers/Tabulation/AdvancementController.php +++ b/app/Http/Controllers/Tabulation/AdvancementController.php @@ -75,6 +75,7 @@ class AdvancementController extends Controller $entry->addFlag('will_advance'); } Cache::forget('audition'.$audition->id.'advancement'); + Cache::forget('publicResultsPage'); return redirect()->route('advancement.ranking', ['audition' => $audition->id])->with('success', 'Passers have been set successfully'); @@ -87,6 +88,7 @@ class AdvancementController extends Controller $entry->removeFlag('will_advance'); } Cache::forget('audition'.$audition->id.'advancement'); + Cache::forget('publicResultsPage'); return redirect()->route('advancement.ranking', ['audition' => $audition->id])->with('success', 'Passers have been cleared successfully');