diff options
author | Joas Schilling <coding@schilljs.com> | 2020-06-05 10:55:28 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2020-06-05 10:55:28 +0300 |
commit | 839bb6104244575453a16087227d8c3af2a21acb (patch) | |
tree | 3f766115615ed1892307c46cd11efd33b71fff5f /lib/Notification/Notifier.php | |
parent | 4a94dcf664b2fcdbf32f4bd58c0a7226099153ff (diff) |
Also cache the participant
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/Notification/Notifier.php')
-rw-r--r-- | lib/Notification/Notifier.php | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php index 9ff13f7a6..bdacd49cb 100644 --- a/lib/Notification/Notifier.php +++ b/lib/Notification/Notifier.php @@ -75,6 +75,8 @@ class Notifier implements INotifier { /** @var Room[] */ protected $rooms = []; + /** @var Participant[][] */ + protected $participants = []; public function __construct(IFactory $lFactory, IURLGenerator $url, @@ -153,6 +155,33 @@ class Notifier implements INotifier { } /** + * @param Room $room + * @param string $userId + * @return Participant + * @throws ParticipantNotFoundException + */ + protected function getParticipant(Room $room, string $userId): Participant { + $roomId = $room->getId(); + if (array_key_exists($roomId, $this->participants) && array_key_exists($userId, $this->participants[$roomId])) { + if ($this->participants[$roomId][$userId] === null) { + throw new ParticipantNotFoundException('Participant does not exist'); + } + + return $this->participants[$roomId][$userId]; + } + + try { + $participant = $room->getParticipant($userId); + $this->participants[$roomId][$userId] = $participant; + return $participant; + } catch (ParticipantNotFoundException $e) { + // Participant does not exist + $this->participants[$roomId][$userId] = null; + throw $e; + } + } + + /** * @param INotification $notification * @param string $languageCode The code of the language that should be used to prepare the notification * @return INotification @@ -186,7 +215,7 @@ class Notifier implements INotifier { // n queries. } else { try { - $participant = $room->getParticipant($userId); + $participant = $this->getParticipant($room, $userId); } catch (ParticipantNotFoundException $e) { // Room does not exist throw new AlreadyProcessedException(); |