Implement better caching of results page.
This commit is contained in:
parent
2bd5d2fff8
commit
01f520b587
|
|
@ -27,5 +27,6 @@ class PublishSeats
|
||||||
}
|
}
|
||||||
$audition->addFlag('seats_published');
|
$audition->addFlag('seats_published');
|
||||||
Cache::forget('resultsSeatList');
|
Cache::forget('resultsSeatList');
|
||||||
|
Cache::forget('publicResultsPage');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ class UnpublishSeats
|
||||||
{
|
{
|
||||||
$audition->removeFlag('seats_published');
|
$audition->removeFlag('seats_published');
|
||||||
Cache::forget('resultsSeatList');
|
Cache::forget('resultsSeatList');
|
||||||
|
Cache::forget('publicResultsPage');
|
||||||
Seat::where('audition_id', $audition->id)->delete();
|
Seat::where('audition_id', $audition->id)->delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ use App\Models\Seat;
|
||||||
use App\Services\AuditionService;
|
use App\Services\AuditionService;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Cache;
|
use Illuminate\Support\Facades\Cache;
|
||||||
|
use Illuminate\Support\Facades\View;
|
||||||
|
|
||||||
use function auditionSetting;
|
use function auditionSetting;
|
||||||
|
|
||||||
|
|
@ -27,6 +28,12 @@ class ResultsPage extends Controller
|
||||||
*/
|
*/
|
||||||
public function __invoke(Request $request)
|
public function __invoke(Request $request)
|
||||||
{
|
{
|
||||||
|
$cacheKey = 'publicResultsPage';
|
||||||
|
|
||||||
|
if (Cache::has($cacheKey)) {
|
||||||
|
return response(Cache::get($cacheKey));
|
||||||
|
}
|
||||||
|
|
||||||
$publishedAdvancementAuditions = [];
|
$publishedAdvancementAuditions = [];
|
||||||
$resultsAdvancementList = [];
|
$resultsAdvancementList = [];
|
||||||
$publishedAuditions = Audition::seatsPublished()
|
$publishedAuditions = Audition::seatsPublished()
|
||||||
|
|
@ -34,7 +41,8 @@ class ResultsPage extends Controller
|
||||||
->with('seats.entry.student')
|
->with('seats.entry.student')
|
||||||
->with('event.ensembles')
|
->with('event.ensembles')
|
||||||
->orderBy('score_order')->get();
|
->orderBy('score_order')->get();
|
||||||
$resultsSeatList = Cache::rememberForever('resultsSeatList', function () use ($publishedAuditions) {
|
$resultsSeatList = Cache::rememberForever('resultsSeatList',
|
||||||
|
function () use ($publishedAuditions) {
|
||||||
$seatList = [];
|
$seatList = [];
|
||||||
// Load the $seatList in the form of $seatlist[audition_id] is an array of seats for that audition
|
// 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
|
// each $seatList[audition_id][] will contain a string with ensemble and seat number and the student object filling it
|
||||||
|
|
@ -60,8 +68,7 @@ class ResultsPage extends Controller
|
||||||
|
|
||||||
if (auditionSetting('advanceTo')) {
|
if (auditionSetting('advanceTo')) {
|
||||||
$publishedAdvancementAuditions = Audition::advancementPublished()->orderBy('score_order')->get();
|
$publishedAdvancementAuditions = Audition::advancementPublished()->orderBy('score_order')->get();
|
||||||
$resultsAdvancementList = Cache::rememberForever('resultsAdvancementList',
|
|
||||||
function () {
|
|
||||||
// get entries with a related flag of will_advance
|
// get entries with a related flag of will_advance
|
||||||
$advancingEntries = Entry::forAdvancement()->with('student.school')
|
$advancingEntries = Entry::forAdvancement()->with('student.school')
|
||||||
->whereHas('flags', function ($query) {
|
->whereHas('flags', function ($query) {
|
||||||
|
|
@ -72,10 +79,21 @@ class ResultsPage extends Controller
|
||||||
return $entry->student->full_name(true);
|
return $entry->student->full_name(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
return $advancingEntries->groupBy('audition_id');
|
$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()
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,7 @@ class AdvancementController extends Controller
|
||||||
$entry->addFlag('will_advance');
|
$entry->addFlag('will_advance');
|
||||||
}
|
}
|
||||||
Cache::forget('audition'.$audition->id.'advancement');
|
Cache::forget('audition'.$audition->id.'advancement');
|
||||||
|
Cache::forget('publicResultsPage');
|
||||||
|
|
||||||
return redirect()->route('advancement.ranking', ['audition' => $audition->id])->with('success',
|
return redirect()->route('advancement.ranking', ['audition' => $audition->id])->with('success',
|
||||||
'Passers have been set successfully');
|
'Passers have been set successfully');
|
||||||
|
|
@ -87,6 +88,7 @@ class AdvancementController extends Controller
|
||||||
$entry->removeFlag('will_advance');
|
$entry->removeFlag('will_advance');
|
||||||
}
|
}
|
||||||
Cache::forget('audition'.$audition->id.'advancement');
|
Cache::forget('audition'.$audition->id.'advancement');
|
||||||
|
Cache::forget('publicResultsPage');
|
||||||
|
|
||||||
return redirect()->route('advancement.ranking', ['audition' => $audition->id])->with('success',
|
return redirect()->route('advancement.ranking', ['audition' => $audition->id])->with('success',
|
||||||
'Passers have been cleared successfully');
|
'Passers have been cleared successfully');
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue