From 3b945385dbf1b3c6e42c18c18752f1fb089f3091 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 25 Apr 2016 15:57:09 +0200 Subject: [PATCH] Load user storage in bulk to minimize performance impact --- .../files/lib/page/MembersListPage.class.php | 60 ++++++++++++------- 1 file changed, 40 insertions(+), 20 deletions(-) diff --git a/wcfsetup/install/files/lib/page/MembersListPage.class.php b/wcfsetup/install/files/lib/page/MembersListPage.class.php index c283e4c307..99fbd24681 100644 --- a/wcfsetup/install/files/lib/page/MembersListPage.class.php +++ b/wcfsetup/install/files/lib/page/MembersListPage.class.php @@ -1,9 +1,11 @@ * @package com.woltlab.wcf * @subpackage page @@ -25,42 +27,42 @@ class MembersListPage extends SortablePage { public static $availableLetters = '#ABCDEFGHIJKLMNOPQRSTUVWXYZ'; /** - * @see \wcf\page\AbstractPage::$neededPermissions + * @inheritDoc */ - public $neededPermissions = array('user.profile.canViewMembersList'); + public $neededPermissions = ['user.profile.canViewMembersList']; /** - * @see \wcf\page\AbstractPage::$neededModules + * @inheritDoc */ - public $neededModules = array('MODULE_MEMBERS_LIST'); + public $neededModules = ['MODULE_MEMBERS_LIST']; /** - * @see \wcf\page\AbstractPage::$enableTracking + * @inheritDoc */ public $enableTracking = true; /** - * @see \wcf\page\MultipleLinkPage::$itemsPerPage + * @inheritDoc */ public $itemsPerPage = MEMBERS_LIST_USERS_PER_PAGE; /** - * @see \wcf\page\SortablePage::$defaultSortField + * @inheritDoc */ public $defaultSortField = MEMBERS_LIST_DEFAULT_SORT_FIELD; /** - * @see \wcf\page\SortablePage::$defaultSortOrder + * @inheritDoc */ public $defaultSortOrder = MEMBERS_LIST_DEFAULT_SORT_ORDER; /** - * @see \wcf\page\SortablePage::$validSortFields + * @inheritDoc */ - public $validSortFields = array('username', 'registrationDate', 'activityPoints', 'likesReceived', 'lastActivityTime'); + public $validSortFields = ['username', 'registrationDate', 'activityPoints', 'likesReceived', 'lastActivityTime']; /** - * @see \wcf\page\MultipleLinkPage::$objectListClassName + * @inheritDoc */ public $objectListClassName = 'wcf\data\user\UserProfileList'; @@ -83,7 +85,7 @@ class MembersListPage extends SortablePage { public $search = null; /** - * @see \wcf\page\IPage::readParameters() + * @inheritDoc */ public function readParameters() { parent::readParameters(); @@ -103,20 +105,20 @@ class MembersListPage extends SortablePage { if (!empty($_POST)) { $parameters = http_build_query($_POST, '', '&'); - HeaderUtil::redirect(LinkHandler::getInstance()->getLink('MembersList', array(), $parameters)); + HeaderUtil::redirect(LinkHandler::getInstance()->getLink('MembersList', [], $parameters)); exit; } } /** - * @see \wcf\page\MultipleLinkPage::initObjectList() + * @inheritDoc */ protected function initObjectList() { parent::initObjectList(); if ($this->search !== null) { $searchData = unserialize($this->search->searchData); - $this->objectList->getConditionBuilder()->add("user_table.userID IN (?)", array($searchData['matches'])); + $this->objectList->getConditionBuilder()->add("user_table.userID IN (?)", [$searchData['matches']]); unset($searchData); } @@ -132,23 +134,41 @@ class MembersListPage extends SortablePage { } } else { - $this->objectList->getConditionBuilder()->add("username LIKE ?", array($this->letter.'%')); + $this->objectList->getConditionBuilder()->add("username LIKE ?", [$this->letter.'%']); } } } /** - * @see \wcf\page\IPage::assignVariables() + * @inheritDoc + */ + protected function readObjects() { + parent::readObjects(); + + $userIDs = []; + /** @var User $user */ + foreach ($this->objectList as $user) { + $userIDs[] = $user->userID; + } + + if (!empty($userIDs)) { + // preload user storage to avoid reading storage for each user separately at runtime + UserStorageHandler::getInstance()->loadStorage($userIDs); + } + } + + /** + * @inheritDoc */ public function assignVariables() { parent::assignVariables(); - WCF::getTPL()->assign(array( + WCF::getTPL()->assign([ 'letters' => str_split(self::$availableLetters), 'letter' => $this->letter, 'searchID' => $this->searchID, 'allowSpidersToIndexThisPage' => true - )); + ]); if (count($this->objectList) === 0) { @header('HTTP/1.0 404 Not Found'); -- 2.20.1