Reduce number of queries for notification access checks
authorMatthias Schmidt <gravatronics@live.com>
Sat, 9 Aug 2014 08:15:59 +0000 (10:15 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Sat, 9 Aug 2014 08:15:59 +0000 (10:15 +0200)
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.

wcfsetup/install/files/lib/system/user/notification/UserNotificationHandler.class.php

index d64d1afa4fabbaf38d88a6a76701747281d2b5de..4510c058334e67f144a0d3db8dec1307f8f35879 100644 (file)
@@ -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