From d142887f178c2c69e24df265a444d903316cbe48 Mon Sep 17 00:00:00 2001 From: joshuaruesweg Date: Tue, 12 Jan 2021 14:45:33 +0100 Subject: [PATCH] Fix performance of user online list If the UserStorageHandler has to load all users that are online, this is quite resource intensive in larger communities and the query is very slow. The UserStorageHandler must actually be loaded so that the permissions of the users can be checked to see if they can make themselves invisible. We switch off this check with this commit and assume that users who cannot change this setting are always online. --- .../lib/data/user/online/UserOnline.class.php | 5 +-- .../user/online/UsersOnlineList.class.php | 36 +++++++------------ 2 files changed, 14 insertions(+), 27 deletions(-) diff --git a/wcfsetup/install/files/lib/data/user/online/UserOnline.class.php b/wcfsetup/install/files/lib/data/user/online/UserOnline.class.php index bc36c76f0e..c478d8c761 100644 --- a/wcfsetup/install/files/lib/data/user/online/UserOnline.class.php +++ b/wcfsetup/install/files/lib/data/user/online/UserOnline.class.php @@ -48,10 +48,7 @@ class UserOnline extends UserProfile { $username = str_replace('%s', $username, $this->userOnlineMarking); } - if ( - $this->getPermission('user.profile.canHideOnlineStatus') - && $this->canViewOnlineStatus == UserProfile::ACCESS_NOBODY - ) { + if ($this->canViewOnlineStatus == UserProfile::ACCESS_NOBODY) { $username .= WCF::getLanguage()->get('wcf.user.usersOnline.invisible'); } diff --git a/wcfsetup/install/files/lib/data/user/online/UsersOnlineList.class.php b/wcfsetup/install/files/lib/data/user/online/UsersOnlineList.class.php index 9aed41014b..f41dd21bdf 100644 --- a/wcfsetup/install/files/lib/data/user/online/UsersOnlineList.class.php +++ b/wcfsetup/install/files/lib/data/user/online/UsersOnlineList.class.php @@ -6,7 +6,6 @@ use wcf\data\user\group\UserGroup; use wcf\data\user\User; use wcf\data\user\UserProfile; use wcf\system\event\EventHandler; -use wcf\system\user\storage\UserStorageHandler; use wcf\system\WCF; use wcf\util\StringUtil; @@ -72,8 +71,6 @@ class UsersOnlineList extends SessionList { $objects = $this->objects; $this->indexToObject = $this->objects = []; - UserStorageHandler::getInstance()->loadStorage($this->objectIDs); - foreach ($objects as $object) { $object = new UserOnline(new User(null, null, $object)); if (!$object->userID || self::isVisibleUser($object)) { @@ -115,8 +112,6 @@ class UsersOnlineList extends SessionList { } } - UserStorageHandler::getInstance()->loadStorage($userIDs); - foreach ($users as $user) { if ($user->canViewOnlineStatus && !self::isVisibleUser($user)) { $this->stats['invisible']++; @@ -219,24 +214,19 @@ class UsersOnlineList extends SessionList { 'userOnline' => $userOnline, ]; - if ($userOnline->getPermission('user.profile.canHideOnlineStatus')) { - switch ($userOnline->canViewOnlineStatus) { - case UserProfile::ACCESS_EVERYONE: - $data['result'] = true; - break; - - case UserProfile::ACCESS_REGISTERED: - if (WCF::getUser()->userID) $data['result'] = true; - break; - - case UserProfile::ACCESS_FOLLOWING: - /** @noinspection PhpUndefinedMethodInspection */ - if (WCF::getUserProfileHandler()->isFollower($userOnline->userID)) $data['result'] = true; - break; - } - } - else { - $data['result'] = true; + switch ($userOnline->canViewOnlineStatus) { + case UserProfile::ACCESS_EVERYONE: + $data['result'] = true; + break; + + case UserProfile::ACCESS_REGISTERED: + if (WCF::getUser()->userID) $data['result'] = true; + break; + + case UserProfile::ACCESS_FOLLOWING: + /** @noinspection PhpUndefinedMethodInspection */ + if (WCF::getUserProfileHandler()->isFollower($userOnline->userID)) $data['result'] = true; + break; } EventHandler::getInstance()->fireAction(get_called_class(), 'isVisibleUser', $data); -- 2.20.1