Fix TODO modifying audition limits should refresh the acceptance limits cache

This commit is contained in:
Matt Young 2024-06-27 15:04:59 -05:00
parent 4201396d03
commit 43889d9587
5 changed files with 124 additions and 1 deletions

View File

@ -0,0 +1,36 @@
<?php
namespace App\Events;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
class SeatingLimitChange
{
use Dispatchable, InteractsWithSockets, SerializesModels;
/**
* Create a new event instance.
*/
public function __construct()
{
//
}
/**
* Get the channels the event should broadcast on.
*
* @return array<int, \Illuminate\Broadcasting\Channel>
*/
public function broadcastOn(): array
{
return [
new PrivateChannel('channel-name'),
];
}
}

View File

@ -0,0 +1,28 @@
<?php
namespace App\Listeners;
use App\Events\SeatingLimitChange;
use App\Services\SeatingService;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
class RefreshSeatingLimitCache
{
protected $seatingService;
/**
* Create the event listener.
*/
public function __construct(SeatingService $seatingService)
{
$this->seatingService = $seatingService;
}
/**
* Handle the event.
*/
public function handle(SeatingLimitChange $event): void
{
$this->seatingService->refreshLimits();
}
}

View File

@ -0,0 +1,49 @@
<?php
namespace App\Observers;
use App\Events\ScoringGuideChange;
use App\Models\SeatingLimit;
class SeatingLimitObserver
{
/**
* Handle the SeatingLimit "created" event.
*/
public function created(SeatingLimit $seatingLimit): void
{
ScoringGuideChange::dispatch();
}
/**
* Handle the SeatingLimit "updated" event.
*/
public function updated(SeatingLimit $seatingLimit): void
{
ScoringGuideChange::dispatch();
}
/**
* Handle the SeatingLimit "deleted" event.
*/
public function deleted(SeatingLimit $seatingLimit): void
{
ScoringGuideChange::dispatch();
}
/**
* Handle the SeatingLimit "restored" event.
*/
public function restored(SeatingLimit $seatingLimit): void
{
ScoringGuideChange::dispatch();
}
/**
* Handle the SeatingLimit "force deleted" event.
*/
public function forceDeleted(SeatingLimit $seatingLimit): void
{
ScoringGuideChange::dispatch();
}
}

View File

@ -6,10 +6,12 @@ use App\Events\AuditionChange;
use App\Events\EntryChange;
use App\Events\ScoreSheetChange;
use App\Events\ScoringGuideChange;
use App\Events\SeatingLimitChange;
use App\Listeners\RefreshAuditionCache;
use App\Listeners\RefreshEntryCache;
use App\Listeners\RefreshScoreSheetCache;
use App\Listeners\RefreshScoringGuideCache;
use App\Listeners\RefreshSeatingLimitCache;
use App\Models\Audition;
use App\Models\Entry;
use App\Models\Room;
@ -17,6 +19,7 @@ use App\Models\RoomUser;
use App\Models\School;
use App\Models\ScoreSheet;
use App\Models\ScoringGuide;
use App\Models\SeatingLimit;
use App\Models\Student;
use App\Models\SubscoreDefinition;
use App\Models\User;
@ -27,6 +30,7 @@ use App\Observers\RoomUserObserver;
use App\Observers\SchoolObserver;
use App\Observers\ScoreSheetObserver;
use App\Observers\ScoringGuideObserver;
use App\Observers\SeatingLimitObserver;
use App\Observers\StudentObserver;
use App\Observers\SubscoreDefinitionObserver;
use App\Observers\UserObserver;
@ -90,6 +94,7 @@ class AppServiceProvider extends ServiceProvider
Student::observe(StudentObserver::class);
SubscoreDefinition::observe(SubscoreDefinitionObserver::class);
User::observe(UserObserver::class);
SeatingLimit::observe(SeatingLimitObserver::class);
Event::listen(
AuditionChange::class,
@ -110,5 +115,10 @@ class AppServiceProvider extends ServiceProvider
ScoreSheetChange::class,
RefreshScoreSheetCache::class
);
Event::listen(
SeatingLimitChange::class,
RefreshSeatingLimitCache::class
);
}
}

View File

@ -23,7 +23,7 @@ class SeatingService
public function getAcceptanceLimits()
{
// TODO modifying audition limits should refresh this cache
// TODO modifying audition limits should refresh the acceptance limits cache
return Cache::remember($this->limitsCacheKey, now()->addDay(), function () {
$limits = SeatingLimit::with('ensemble')->get();
// Sort limits by ensemble->rank