diff options
author | Joas Schilling <coding@schilljs.com> | 2022-02-28 17:27:22 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2022-03-14 15:46:05 +0300 |
commit | 61fc1264f199a16ee0560769743d7cfc32140656 (patch) | |
tree | ddb10f1112f058b4dad7f1a75bff7b0a7ee3b5ef /lib | |
parent | b8ccba1dd3ea56daf5c3205f55e3eb17c01a026f (diff) |
Defer preparing of payloads when we don't push anyway
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Push.php | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/Push.php b/lib/Push.php index b8716fc..3c446ae 100644 --- a/lib/Push.php +++ b/lib/Push.php @@ -72,8 +72,15 @@ class Push { protected $output; /** @var array */ protected $payloadsToSend = []; + + /** @var bool */ + protected $deferPreparing = false; /** @var bool */ protected $deferPayloads = false; + /** @var array[] */ + protected $deletesToPush = []; + /** @var INotification[] */ + protected $notificationsToPush = []; /** @var null[]|IUserStatus[] */ protected $userStatuses = []; @@ -117,10 +124,27 @@ class Push { } public function deferPayloads(): void { + $this->deferPreparing = true; $this->deferPayloads = true; } public function flushPayloads(): void { + $this->deferPreparing = false; + + if (!empty($this->notificationsToPush)) { + foreach ($this->notificationsToPush as $id => $notification) { + $this->pushToDevice($id, $notification); + } + $this->notificationsToPush = []; + } + + if (!empty($this->deletesToPush)) { + foreach ($this->deletesToPush as $id => $data) { + $this->pushDeleteToDevice($data['userId'], $id, $data['app']); + } + $this->deletesToPush = []; + } + $this->deferPayloads = false; $this->sendNotificationsToProxies(); } @@ -159,6 +183,11 @@ class Push { return; } + if ($this->deferPreparing) { + $this->notificationsToPush[$id] = clone $notification; + return; + } + $user = $this->createFakeUserObject($notification->getUser()); if (!array_key_exists($notification->getUser(), $this->userStatuses)) { @@ -252,6 +281,11 @@ class Push { return; } + if ($this->deferPreparing) { + $this->deletesToPush[$notificationId] = ['userId' => $userId, 'app' => $app]; + return; + } + $user = $this->createFakeUserObject($userId); if (!array_key_exists($userId, $this->userDevices)) { |