tabulationService = $tabulationService; } public function getAcceptanceLimits() { // TODO modifying audition limits should refresh this cache return Cache::remember($this->limitsCacheKey, now()->addDay(), function () { $limits = SeatingLimit::with('ensemble')->get(); // Sort limits by ensemble->rank $limits = $limits->sortBy(function ($limit) { return $limit->ensemble->rank; }); return $limits->groupBy('audition_id'); }); } public function getLimitForAudition($auditionId) { if (! $this->getAcceptanceLimits()->has($auditionId)) { return new \Illuminate\Database\Eloquent\Collection(); } return $this->getAcceptanceLimits()[$auditionId]; } public function refreshLimits(): void { Cache::forget($this->limitsCacheKey); } public function getSeatableEntries($auditionId) { $entries = $this->tabulationService->auditionEntries($auditionId); return $entries->reject(function ($entry) { return $entry->hasFlag('declined'); }); } public function getSeatsForAudition($auditionId) { $cacheKey = 'audition'.$auditionId.'seats'; // TODO rework to pull entry info from cache return Cache::remember($cacheKey, now()->addHour(), function () use ($auditionId) { return Seat::with('entry.student.school') ->where('audition_id', $auditionId) ->orderBy('seat') ->get() ->groupBy('ensemble_id'); }); } public function forgetSeatsForAudition($auditionId) { $cacheKey = 'audition'.$auditionId.'seats'; Cache::forget($cacheKey); } public function getEnsemblesForEvent($eventId) { static $eventEnsembles = []; if (array_key_exists($eventId, $eventEnsembles)) { return $eventEnsembles[$eventId]; } $event = Event::find($eventId); $eventEnsembles[$eventId] = $event->ensembles; return $eventEnsembles[$eventId]; } }