From e95e11ee583002bde5fca4c3d3777d98383ce644 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Sat, 9 Aug 2014 10:15:59 +0200 Subject: [PATCH] Reduce number of queries for notification access checks If the access check relies on data that needs to be fetched from the database, `AbstractSharedUserNotificationEvent::prepare()` has only be called for the current object, not all objects which causes queries for each object separately instead of one query for all objects. --- .../notification/UserNotificationHandler.class.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/wcfsetup/install/files/lib/system/user/notification/UserNotificationHandler.class.php b/wcfsetup/install/files/lib/system/user/notification/UserNotificationHandler.class.php index d64d1afa4f..4510c05833 100644 --- a/wcfsetup/install/files/lib/system/user/notification/UserNotificationHandler.class.php +++ b/wcfsetup/install/files/lib/system/user/notification/UserNotificationHandler.class.php @@ -385,10 +385,6 @@ class UserNotificationHandler extends SingletonFactory { $notification->additionalData ); - if (!$class->checkAccess()) { - continue; - } - if (isset($authorToNotification[$notification->notificationID])) { $eventAuthors = array(); foreach ($authorToNotification[$notification->notificationID] as $userID) { @@ -418,6 +414,13 @@ class UserNotificationHandler extends SingletonFactory { $notifications[] = $data; } + // check access + foreach ($notifications as $index => $notificationData) { + if (!$notificationData['event']->checkAccess()) { + unset($notifications[$index]); + } + } + return array( 'count' => count($notifications), 'notifications' => $notifications -- 2.20.1