diff options
author | Joas Schilling <coding@schilljs.com> | 2022-02-28 17:15:58 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2022-03-14 15:46:05 +0300 |
commit | 7d1394b0dae829dbb66d103a689e39d66c4916dd (patch) | |
tree | 431132bcbc1765bf9e866d80952bd112f9229c7f /lib | |
parent | 002c1c5834721a9af0a4b0ef0c860ceb25d6ac8a (diff) |
Only load the user status once per user
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Push.php | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/lib/Push.php b/lib/Push.php index f516699..e82e21b 100644 --- a/lib/Push.php +++ b/lib/Push.php @@ -75,6 +75,9 @@ class Push { /** @var bool */ protected $deferPayloads = false; + /** @var null[]|IUserStatus[] */ + protected $userStatuses = []; + public function __construct(IDBConnection $connection, INotificationManager $notificationManager, IConfig $config, @@ -156,12 +159,16 @@ class Push { $user = $this->createFakeUserObject($notification->getUser()); - $userStatus = $this->userStatusManager->getUserStatuses([ - $notification->getUser(), - ]); + if (!array_key_exists($notification->getUser(), $this->userStatuses)) { + $userStatus = $this->userStatusManager->getUserStatuses([ + $notification->getUser(), + ]); + + $this->userStatuses[$notification->getUser()] = $userStatus[$notification->getUser()] ?? null; + } - if (isset($userStatus[$notification->getUser()])) { - $userStatus = $userStatus[$notification->getUser()]; + if (isset($this->userStatuses[$notification->getUser()])) { + $userStatus = $this->userStatuses[$notification->getUser()]; if ($userStatus->getStatus() === IUserStatus::DND) { $this->printInfo('<error>User status is set to DND - no push notifications will be sent</error>'); return; |