Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/spreed.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2020-06-05 10:55:28 +0300
committerJoas Schilling <coding@schilljs.com>2020-06-05 10:55:28 +0300
commit839bb6104244575453a16087227d8c3af2a21acb (patch)
tree3f766115615ed1892307c46cd11efd33b71fff5f /lib/Notification
parent4a94dcf664b2fcdbf32f4bd58c0a7226099153ff (diff)
Also cache the participant
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/Notification')
-rw-r--r--lib/Notification/Notifier.php31
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();