Projectors send too many messages to mercure
This is code from the ScoreBoardProjector:
public function __invoke(Event $event): void
{
parent::__invoke($event);
if ($event instanceof TableAwareEvent) {
$this->notifier->notify(
new ScoreLogUpdateNotification($event->getTableIdentifier()),
);
return;
}
// I wish I had provided a TableIdentifier in every event this projector listens to.
if ($event instanceof SheetAffectingEvent) {
$tableIdentifier = $this->tablesBySheet->getTableByScoreSheet(
$event->getScoreSheetIdentifier()
);
$this->notifier->notify(
new ScoreLogUpdateNotification($tableIdentifier),
);
}
}
This sends a notification to the notifier on every TableAwareEvent
and every SheetAffectingEvent
, even if the projector doesn't do anything with the event. We should emit a notification in the concrete handler methods, and only if something has effectively changed.
This should be fixed in every notifying projector.