Remove events and listeners

This commit is contained in:
Matt Young 2024-07-09 10:42:24 -05:00
parent af837264e9
commit a1a9744305
21 changed files with 54 additions and 425 deletions

View File

@ -1,36 +0,0 @@
<?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 AuditionChange
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public bool $refreshCache;
/**
* Create a new event instance.
*/
public function __construct(bool $refreshCache = false)
{
$this->refreshCache = $refreshCache;
}
/**
* 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

@ -1,36 +0,0 @@
<?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 EntryChange
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public int $auditionId;
/**
* Create a new event instance.
*/
public function __construct($auditionId = null)
{
$this->auditionId = $auditionId;
}
/**
* 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

@ -1,36 +0,0 @@
<?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 ScoreSheetChange
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public int $entryId;
/**
* Create a new event instance.
*/
public function __construct($entryId = null)
{
$this->entryId = $entryId;
}
/**
* 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

@ -1,36 +0,0 @@
<?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 ScoringGuideChange
{
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

@ -1,36 +0,0 @@
<?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

@ -37,6 +37,7 @@ class TabulationController extends Controller
public function status() public function status()
{ {
// Needs to provide a collection of auditions
$auditions = $this->tabulationService->getAuditionsWithStatus('seating'); $auditions = $this->tabulationService->getAuditionsWithStatus('seating');
return view('tabulation.status', compact('auditions')); return view('tabulation.status', compact('auditions'));

View File

@ -1,31 +0,0 @@
<?php
namespace App\Listeners;
use App\Events\AuditionChange;
use App\Services\AuditionService;
class RefreshAuditionCache
{
protected $auditionService;
/**
* Create the event listener.
*/
public function __construct(AuditionService $cacheService)
{
$this->auditionService = $cacheService;
}
/**
* Handle the event.
*/
public function handle(AuditionChange $event): void
{
if ($event->refreshCache) {
$this->auditionService->refreshCache();
} else {
$this->auditionService->clearCache();
}
}
}

View File

@ -1,34 +0,0 @@
<?php
namespace App\Listeners;
use App\Events\AuditionChange;
use App\Events\EntryChange;
use App\Services\AuditionService;
use App\Services\EntryService;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
class RefreshEntryCache
{
protected $entryService;
/**
* Create the event listener.
*/
public function __construct(EntryService $cacheService)
{
$this->entryService = $cacheService;
}
/**
* Handle the event.
*/
public function handle(EntryChange $event): void
{
if ($event->auditionId) {
$this->entryService->clearEntryCacheForAudition($event->auditionId);
} else {
$this->entryService->clearEntryCaches();
}
}
}

View File

@ -1,35 +0,0 @@
<?php
namespace App\Listeners;
use App\Events\ScoreSheetChange;
use App\Services\ScoreService;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
class RefreshScoreSheetCache
{
protected $scoreService;
/**
* Create the event listener.
*/
public function __construct(ScoreService $scoreService)
{
$this->scoreService = $scoreService;
}
/**
* Handle the event.
*/
public function handle(ScoreSheetChange $event): void
{
$this->scoreService->clearScoreSheetCountCache();
if ($event->entryId) {
$this->scoreService->clearEntryTotalScoresCache($event->entryId);
}
// If we are in local environment, send a success flash message
if (config('app.env') === 'local') {
session()->flash('success','Cleared cache for entry ID ' . $event->entryId);
}
}
}

View File

@ -1,29 +0,0 @@
<?php
namespace App\Listeners;
use App\Events\ScoringGuideChange;
use App\Services\ScoreService;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
class RefreshScoringGuideCache
{
protected $scoreService;
/**
* Create the event listener.
*/
public function __construct(ScoreService $scoreService)
{
$this->scoreService = $scoreService;
}
/**
* Handle the event.
*/
public function handle(ScoringGuideChange $event): void
{
$this->scoreService->clearScoringGuideCache();
$this->scoreService->clearAllCachedTotalScores();
}
}

View File

@ -1,28 +0,0 @@
<?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

@ -13,8 +13,7 @@ class AuditionObserver
*/ */
public function created(Audition $audition): void public function created(Audition $audition): void
{ {
AuditionChange::dispatch(); //
EntryChange::dispatch($audition->id);
} }
/** /**
@ -22,8 +21,7 @@ class AuditionObserver
*/ */
public function updated(Audition $audition): void public function updated(Audition $audition): void
{ {
AuditionChange::dispatch(); //
EntryChange::dispatch($audition->id);
} }
/** /**
@ -31,8 +29,7 @@ class AuditionObserver
*/ */
public function deleted(Audition $audition): void public function deleted(Audition $audition): void
{ {
AuditionChange::dispatch(); //
EntryChange::dispatch($audition->id);
} }
/** /**
@ -40,8 +37,7 @@ class AuditionObserver
*/ */
public function restored(Audition $audition): void public function restored(Audition $audition): void
{ {
AuditionChange::dispatch(); //
EntryChange::dispatch($audition->id);
} }
/** /**
@ -49,7 +45,6 @@ class AuditionObserver
*/ */
public function forceDeleted(Audition $audition): void public function forceDeleted(Audition $audition): void
{ {
AuditionChange::dispatch(); //
EntryChange::dispatch($audition->id);
} }
} }

View File

@ -20,7 +20,7 @@ class RoomObserver
*/ */
public function updated(Room $room): void public function updated(Room $room): void
{ {
AuditionChange::dispatch(); //
} }
/** /**
@ -28,7 +28,7 @@ class RoomObserver
*/ */
public function deleted(Room $room): void public function deleted(Room $room): void
{ {
AuditionChange::dispatch(); //
} }
/** /**
@ -36,7 +36,7 @@ class RoomObserver
*/ */
public function restored(Room $room): void public function restored(Room $room): void
{ {
AuditionChange::dispatch(); //
} }
/** /**
@ -44,6 +44,6 @@ class RoomObserver
*/ */
public function forceDeleted(Room $room): void public function forceDeleted(Room $room): void
{ {
AuditionChange::dispatch(); //
} }
} }

View File

@ -12,7 +12,7 @@ class RoomUserObserver
*/ */
public function created(RoomUser $roomUser): void public function created(RoomUser $roomUser): void
{ {
AuditionChange::dispatch(); //
} }
/** /**
@ -20,7 +20,7 @@ class RoomUserObserver
*/ */
public function updated(RoomUser $roomUser): void public function updated(RoomUser $roomUser): void
{ {
AuditionChange::dispatch(); //
} }
/** /**
@ -28,7 +28,7 @@ class RoomUserObserver
*/ */
public function deleted(RoomUser $roomUser): void public function deleted(RoomUser $roomUser): void
{ {
AuditionChange::dispatch(); //
} }
/** /**
@ -36,7 +36,7 @@ class RoomUserObserver
*/ */
public function restored(RoomUser $roomUser): void public function restored(RoomUser $roomUser): void
{ {
AuditionChange::dispatch(); //
} }
/** /**
@ -44,6 +44,6 @@ class RoomUserObserver
*/ */
public function forceDeleted(RoomUser $roomUser): void public function forceDeleted(RoomUser $roomUser): void
{ {
AuditionChange::dispatch(); //
} }
} }

View File

@ -12,7 +12,7 @@ class ScoreSheetObserver
*/ */
public function created(ScoreSheet $scoreSheet): void public function created(ScoreSheet $scoreSheet): void
{ {
ScoreSheetChange::dispatch($scoreSheet->entry_id); //
} }
/** /**
@ -20,7 +20,7 @@ class ScoreSheetObserver
*/ */
public function updated(ScoreSheet $scoreSheet): void public function updated(ScoreSheet $scoreSheet): void
{ {
ScoreSheetChange::dispatch($scoreSheet->entry_id); //
} }
/** /**
@ -28,7 +28,7 @@ class ScoreSheetObserver
*/ */
public function deleted(ScoreSheet $scoreSheet): void public function deleted(ScoreSheet $scoreSheet): void
{ {
ScoreSheetChange::dispatch($scoreSheet->entry_id); //
} }
/** /**
@ -36,7 +36,7 @@ class ScoreSheetObserver
*/ */
public function restored(ScoreSheet $scoreSheet): void public function restored(ScoreSheet $scoreSheet): void
{ {
ScoreSheetChange::dispatch($scoreSheet->entry_id); //
} }
/** /**
@ -44,6 +44,6 @@ class ScoreSheetObserver
*/ */
public function forceDeleted(ScoreSheet $scoreSheet): void public function forceDeleted(ScoreSheet $scoreSheet): void
{ {
ScoreSheetChange::dispatch($scoreSheet->entry_id); //
} }
} }

View File

@ -13,7 +13,7 @@ class ScoringGuideObserver
*/ */
public function created(ScoringGuide $scoringGuide): void public function created(ScoringGuide $scoringGuide): void
{ {
ScoringGuideChange::dispatch(); //
} }
/** /**
@ -21,8 +21,7 @@ class ScoringGuideObserver
*/ */
public function updated(ScoringGuide $scoringGuide): void public function updated(ScoringGuide $scoringGuide): void
{ {
AuditionChange::dispatch(); //
ScoringGuideChange::dispatch();
} }
/** /**
@ -30,8 +29,7 @@ class ScoringGuideObserver
*/ */
public function deleted(ScoringGuide $scoringGuide): void public function deleted(ScoringGuide $scoringGuide): void
{ {
AuditionChange::dispatch(); //
ScoringGuideChange::dispatch();
} }
/** /**
@ -39,8 +37,7 @@ class ScoringGuideObserver
*/ */
public function restored(ScoringGuide $scoringGuide): void public function restored(ScoringGuide $scoringGuide): void
{ {
AuditionChange::dispatch(); //
ScoringGuideChange::dispatch();
} }
/** /**
@ -48,7 +45,6 @@ class ScoringGuideObserver
*/ */
public function forceDeleted(ScoringGuide $scoringGuide): void public function forceDeleted(ScoringGuide $scoringGuide): void
{ {
AuditionChange::dispatch(); //
ScoringGuideChange::dispatch();
} }
} }

View File

@ -12,7 +12,7 @@ class SeatingLimitObserver
*/ */
public function created(SeatingLimit $seatingLimit): void public function created(SeatingLimit $seatingLimit): void
{ {
ScoringGuideChange::dispatch(); //
} }
/** /**
@ -20,7 +20,7 @@ class SeatingLimitObserver
*/ */
public function updated(SeatingLimit $seatingLimit): void public function updated(SeatingLimit $seatingLimit): void
{ {
ScoringGuideChange::dispatch(); //
} }
/** /**
@ -28,7 +28,7 @@ class SeatingLimitObserver
*/ */
public function deleted(SeatingLimit $seatingLimit): void public function deleted(SeatingLimit $seatingLimit): void
{ {
ScoringGuideChange::dispatch(); //
} }
/** /**
@ -36,7 +36,7 @@ class SeatingLimitObserver
*/ */
public function restored(SeatingLimit $seatingLimit): void public function restored(SeatingLimit $seatingLimit): void
{ {
ScoringGuideChange::dispatch(); //
} }
/** /**
@ -44,6 +44,6 @@ class SeatingLimitObserver
*/ */
public function forceDeleted(SeatingLimit $seatingLimit): void public function forceDeleted(SeatingLimit $seatingLimit): void
{ {
ScoringGuideChange::dispatch(); //
} }
} }

View File

@ -13,8 +13,7 @@ class SubscoreDefinitionObserver
*/ */
public function created(SubscoreDefinition $subscoreDefinition): void public function created(SubscoreDefinition $subscoreDefinition): void
{ {
AuditionChange::dispatch(); //
ScoringGuideChange::dispatch();
} }
/** /**
@ -22,8 +21,7 @@ class SubscoreDefinitionObserver
*/ */
public function updated(SubscoreDefinition $subscoreDefinition): void public function updated(SubscoreDefinition $subscoreDefinition): void
{ {
AuditionChange::dispatch(); //
ScoringGuideChange::dispatch();
} }
/** /**
@ -31,8 +29,7 @@ class SubscoreDefinitionObserver
*/ */
public function deleted(SubscoreDefinition $subscoreDefinition): void public function deleted(SubscoreDefinition $subscoreDefinition): void
{ {
AuditionChange::dispatch(); //
ScoringGuideChange::dispatch();
} }
/** /**
@ -40,8 +37,7 @@ class SubscoreDefinitionObserver
*/ */
public function restored(SubscoreDefinition $subscoreDefinition): void public function restored(SubscoreDefinition $subscoreDefinition): void
{ {
AuditionChange::dispatch(); //
ScoringGuideChange::dispatch();
} }
/** /**
@ -49,7 +45,6 @@ class SubscoreDefinitionObserver
*/ */
public function forceDeleted(SubscoreDefinition $subscoreDefinition): void public function forceDeleted(SubscoreDefinition $subscoreDefinition): void
{ {
AuditionChange::dispatch(); //
ScoringGuideChange::dispatch();
} }
} }

View File

@ -20,7 +20,7 @@ class UserObserver
*/ */
public function updated(User $user): void public function updated(User $user): void
{ {
AuditionChange::dispatch(); //
} }
/** /**
@ -28,7 +28,7 @@ class UserObserver
*/ */
public function deleted(User $user): void public function deleted(User $user): void
{ {
AuditionChange::dispatch(); //
} }
/** /**
@ -44,6 +44,6 @@ class UserObserver
*/ */
public function forceDeleted(User $user): void public function forceDeleted(User $user): void
{ {
AuditionChange::dispatch(); //
} }
} }

View File

@ -102,29 +102,6 @@ class AppServiceProvider extends ServiceProvider
User::observe(UserObserver::class); User::observe(UserObserver::class);
SeatingLimit::observe(SeatingLimitObserver::class); SeatingLimit::observe(SeatingLimitObserver::class);
Event::listen(
AuditionChange::class,
RefreshAuditionCache::class
);
Event::listen(
EntryChange::class,
RefreshEntryCache::class
);
Event::listen(
ScoringGuideChange::class,
RefreshScoringGuideCache::class
);
Event::listen(
ScoreSheetChange::class,
RefreshScoreSheetCache::class
);
Event::listen(
SeatingLimitChange::class,
RefreshSeatingLimitCache::class
);
} }
} }

View File

@ -5,9 +5,7 @@ namespace App\Services;
use App\Models\Audition; use App\Models\Audition;
use App\Models\ScoringGuide; use App\Models\ScoringGuide;
use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Session;
class AuditionService class AuditionService
{ {
@ -28,19 +26,20 @@ class AuditionService
public function getAuditions($mode = 'seating'): \Illuminate\Database\Eloquent\Collection public function getAuditions($mode = 'seating'): \Illuminate\Database\Eloquent\Collection
{ {
$auditions = Cache::remember($this->cacheKey, 3600, function () { $auditions = Cache::remember($this->cacheKey, 3600, function () {
if (App::environment('local')) {
Session::flash('success', 'Audition Cache Updated');
}
return Audition::with(['scoringGuide.subscores', 'judges']) return Audition::with(['scoringGuide.subscores', 'judges'])
->withCount('judges') ->withCount('judges')
->withCount('entries') ->withCount('entries')
->withCount(['entries as seating_entries_count' => function (Builder $query) { ->withCount([
'entries as seating_entries_count' => function (Builder $query) {
$query->where('for_seating', true); $query->where('for_seating', true);
}]) },
->withCount(['entries as advancement_entries_count' => function (Builder $query) { ])
->withCount([
'entries as advancement_entries_count' => function (Builder $query) {
$query->where('for_advancement', true); $query->where('for_advancement', true);
}]) },
])
->orderBy('score_order') ->orderBy('score_order')
->get() ->get()
->keyBy('id'); ->keyBy('id');
@ -80,18 +79,21 @@ class AuditionService
$cacheKey, $cacheKey,
now()->addHour(), now()->addHour(),
function () { function () {
return Audition::with('flags')->orderBy('score_order')->get()->filter(fn ($audition) => $audition->hasFlag('seats_published')); return Audition::with('flags')->orderBy('score_order')->get()->filter(fn ($audition
) => $audition->hasFlag('seats_published'));
}); });
} }
public function getPublishedAdvancementAuditions() public function getPublishedAdvancementAuditions()
{ {
$cacheKey = 'publishedAdvancementAuditions'; $cacheKey = 'publishedAdvancementAuditions';
return Cache::remember( return Cache::remember(
$cacheKey, $cacheKey,
now()->addHour(), now()->addHour(),
function () { function () {
return Audition::with('flags')->orderBy('score_order')->get()->filter(fn ($audition) => $audition->hasFlag('advancement_published')); return Audition::with('flags')->orderBy('score_order')->get()->filter(fn ($audition
) => $audition->hasFlag('advancement_published'));
}); });
} }