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-04 18:18:24 +0300
committerJoas Schilling <coding@schilljs.com>2020-06-04 18:18:24 +0300
commit97777821886b364c23a2157d5de5f57e4be119a0 (patch)
tree2727bada8127cbb120d102eca96946f2cd1ff9e0 /lib/Notification/Notifier.php
parentc2ab3395aa8522cf25eeebc40a99c72f8b332b28 (diff)
Temporarily cache the rooms in the notifier
If we have multiple notifications to render for the same room we only do 1 query now. This e.g. heavily impacts the performance when creating "X started a call" push notifications. Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/Notification/Notifier.php')
-rw-r--r--lib/Notification/Notifier.php46
1 files changed, 38 insertions, 8 deletions
diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php
index c336103e6..092cf186b 100644
--- a/lib/Notification/Notifier.php
+++ b/lib/Notification/Notifier.php
@@ -73,6 +73,9 @@ class Notifier implements INotifier {
/** @var Definitions */
protected $definitions;
+ /** @var Room[] */
+ protected $rooms = [];
+
public function __construct(IFactory $lFactory,
IURLGenerator $url,
Config $config,
@@ -118,6 +121,38 @@ class Notifier implements INotifier {
}
/**
+ * @param string $objectId
+ * @return Room
+ * @throws RoomNotFoundException
+ */
+ protected function getRoom(string $objectId): Room {
+ if (array_key_exists($objectId, $this->rooms)) {
+ if ($this->rooms[$objectId] === null) {
+ throw new RoomNotFoundException('Room does not exist');
+ }
+
+ return $this->rooms[$objectId];
+ }
+
+ try {
+ $room = $this->manager->getRoomByToken($objectId);
+ $this->rooms[$objectId] = $room;
+ return $room;
+ } catch (RoomNotFoundException $e) {
+ try {
+ // Before 3.2.3 the id was passed in notifications
+ $room = $this->manager->getRoomById((int) $objectId);
+ $this->rooms[$objectId] = $room;
+ return $room;
+ } catch (RoomNotFoundException $e) {
+ // Room does not exist
+ $this->rooms[$objectId] = null;
+ throw $e;
+ }
+ }
+ }
+
+ /**
* @param INotification $notification
* @param string $languageCode The code of the language that should be used to prepare the notification
* @return INotification
@@ -138,15 +173,10 @@ class Notifier implements INotifier {
$l = $this->lFactory->get('spreed', $languageCode);
try {
- $room = $this->manager->getRoomByToken($notification->getObjectId());
+ $room = $this->getRoom($notification->getObjectId());
} catch (RoomNotFoundException $e) {
- try {
- // Before 3.2.3 the id was passed in notifications
- $room = $this->manager->getRoomById((int) $notification->getObjectId());
- } catch (RoomNotFoundException $e) {
- // Room does not exist
- throw new AlreadyProcessedException();
- }
+ // Room does not exist
+ throw new AlreadyProcessedException();
}
try {