From ac23d79fe7e155506945666544abb7884388d7cd Mon Sep 17 00:00:00 2001 From: Sami Mazouz Date: Mon, 18 Jul 2022 15:17:46 +0100 Subject: [PATCH] fix: unread notifications are globally cached between users. (#3543) Signed-off-by: Sami Mazouz --- framework/core/src/User/User.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/framework/core/src/User/User.php b/framework/core/src/User/User.php index cc1ac95c8..05ee35394 100644 --- a/framework/core/src/User/User.php +++ b/framework/core/src/User/User.php @@ -449,10 +449,10 @@ class User extends AbstractModel */ protected function getUnreadNotifications() { - static $cached = null; + static $cached = []; - if (is_null($cached)) { - $cached = $this->notifications() + if (! isset($cached[$this->id])) { + $cached[$this->id] = $this->notifications() ->whereIn('type', $this->getAlertableNotificationTypes()) ->whereNull('read_at') ->where('is_deleted', false) @@ -460,7 +460,7 @@ class User extends AbstractModel ->get(); } - return $cached; + return $cached[$this->id]; } /**