From: Matthias Schmidt Date: Sun, 24 May 2015 11:05:58 +0000 (+0200) Subject: Add UserProfileCache X-Git-Tag: 3.0.0_Beta_1~2325 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=3b5fb8efcc37666f2afe20fc4d2ce8a2883afc56;p=GitHub%2FWoltLab%2FWCF.git Add UserProfileCache --- diff --git a/CHANGELOG.md b/CHANGELOG.md index 064cb5d3ce..39be1748cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### 2.2.0 Alpha 1 (XXXX-YY-ZZ) +* `wcf\data\user\UserProfileCache` for caching user profiles during runtime. * instruction file name for most PIPs has default value provided by `wcf\system\package\plugin\IPackageInstallationPlugin::getDefaultFilename()`. * `options` support for cronjobs. * `name` attribute for cronjob PIP (`cronjobName` for cronjob objects). diff --git a/wcfsetup/install/files/lib/data/TLegacyUserPropertyAccess.class.php b/wcfsetup/install/files/lib/data/TLegacyUserPropertyAccess.class.php new file mode 100644 index 0000000000..399b65b975 --- /dev/null +++ b/wcfsetup/install/files/lib/data/TLegacyUserPropertyAccess.class.php @@ -0,0 +1,35 @@ + + * @package com.woltlab.wcf + * @subpackage data.user + * @category Community Framework + * @deprecated + */ +trait TLegacyUserPropertyAccess { + /** + * @see \wcf\data\IStorableObject::__get() + */ + public function __get($name) { + $value = parent::__get($name); + if ($value !== null) { + return $value; + } + else if (!($this instanceof DatabaseObjectDecorator) && array_key_exists($name, $this->data)) { + return null; + } + else if ($this instanceof DatabaseObjectDecorator && array_key_exists($name, $this->object->data)) { + return null; + } + + // in case any code should rely on directly accessing user properties, + // refer them to the user profile object + return $this->getUserProfile()->$name; + } +} diff --git a/wcfsetup/install/files/lib/data/comment/CommentAction.class.php b/wcfsetup/install/files/lib/data/comment/CommentAction.class.php index 58f6b011a7..9be651011f 100644 --- a/wcfsetup/install/files/lib/data/comment/CommentAction.class.php +++ b/wcfsetup/install/files/lib/data/comment/CommentAction.class.php @@ -630,12 +630,6 @@ class CommentAction extends AbstractDatabaseObjectAction { $comment->setIsDeletable($this->commentProcessor->canDeleteComment($comment->getDecoratedObject())); $comment->setIsEditable($this->commentProcessor->canEditComment($comment->getDecoratedObject())); - // set user profile - if ($comment->userID) { - $userProfile = UserProfile::getUserProfile($comment->userID); - $comment->setUserProfile($userProfile); - } - WCF::getTPL()->assign(array( 'commentList' => array($comment), 'commentManager' => $this->commentProcessor @@ -654,12 +648,6 @@ class CommentAction extends AbstractDatabaseObjectAction { $response->setIsDeletable($this->commentProcessor->canDeleteResponse($response->getDecoratedObject())); $response->setIsEditable($this->commentProcessor->canEditResponse($response->getDecoratedObject())); - // set user profile - if ($response->userID) { - $userProfile = UserProfile::getUserProfile($response->userID); - $response->setUserProfile($userProfile); - } - // render response WCF::getTPL()->assign(array( 'responseList' => array($response), diff --git a/wcfsetup/install/files/lib/data/comment/StructuredComment.class.php b/wcfsetup/install/files/lib/data/comment/StructuredComment.class.php index 18de999aa0..1aca1fd789 100644 --- a/wcfsetup/install/files/lib/data/comment/StructuredComment.class.php +++ b/wcfsetup/install/files/lib/data/comment/StructuredComment.class.php @@ -3,6 +3,7 @@ namespace wcf\data\comment; use wcf\data\comment\response\StructuredCommentResponse; use wcf\data\user\User; use wcf\data\user\UserProfile; +use wcf\data\user\UserProfileCache; use wcf\data\DatabaseObjectDecorator; /** @@ -103,7 +104,14 @@ class StructuredComment extends DatabaseObjectDecorator implements \Countable, \ */ public function getUserProfile() { if ($this->userProfile === null) { - $this->userProfile = new UserProfile(new User(null, $this->data)); + if ($this->userID) { + $this->userProfile = UserProfileCache::getInstance()->getUserProfile($this->userID); + } + else { + $this->userProfile = new UserProfile(new User(null, array( + 'username' => $this->username + ))); + } } return $this->userProfile; diff --git a/wcfsetup/install/files/lib/data/comment/StructuredCommentList.class.php b/wcfsetup/install/files/lib/data/comment/StructuredCommentList.class.php index fe33bc3180..a78d9f6beb 100644 --- a/wcfsetup/install/files/lib/data/comment/StructuredCommentList.class.php +++ b/wcfsetup/install/files/lib/data/comment/StructuredCommentList.class.php @@ -2,7 +2,7 @@ namespace wcf\data\comment; use wcf\data\comment\response\CommentResponseList; use wcf\data\comment\response\StructuredCommentResponse; -use wcf\data\user\UserProfile; +use wcf\data\user\UserProfileCache; use wcf\system\comment\manager\ICommentManager; use wcf\system\like\LikeHandler; @@ -125,22 +125,9 @@ class StructuredCommentList extends CommentList { } } - // fetch user data and avatars + // cache user ids if (!empty($userIDs)) { - $userIDs = array_unique($userIDs); - - $users = UserProfile::getUserProfiles($userIDs); - foreach ($this->objects as $comment) { - if ($comment->userID && isset($users[$comment->userID])) { - $comment->setUserProfile($users[$comment->userID]); - } - - foreach ($comment as $response) { - if ($response->userID && isset($users[$response->userID])) { - $response->setUserProfile($users[$response->userID]); - } - } - } + UserProfileCache::getInstance()->cacheUserIDs(array_unique($userIDs)); } } diff --git a/wcfsetup/install/files/lib/data/comment/ViewableComment.class.php b/wcfsetup/install/files/lib/data/comment/ViewableComment.class.php index 2036c37b71..f505207ce8 100644 --- a/wcfsetup/install/files/lib/data/comment/ViewableComment.class.php +++ b/wcfsetup/install/files/lib/data/comment/ViewableComment.class.php @@ -2,7 +2,9 @@ namespace wcf\data\comment; use wcf\data\user\User; use wcf\data\user\UserProfile; +use wcf\data\user\UserProfileCache; use wcf\data\DatabaseObjectDecorator; +use wcf\data\TLegacyUserPropertyAccess; /** * Represents a viewable comment. @@ -15,6 +17,8 @@ use wcf\data\DatabaseObjectDecorator; * @category Community Framework */ class ViewableComment extends DatabaseObjectDecorator { + use TLegacyUserPropertyAccess; + /** * @see \wcf\data\DatabaseObjectDecorator::$baseClass */ @@ -33,7 +37,14 @@ class ViewableComment extends DatabaseObjectDecorator { */ public function getUserProfile() { if ($this->userProfile === null) { - $this->userProfile = new UserProfile(new User(null, $this->getDecoratedObject()->data)); + if ($this->userID) { + $this->userProfile = UserProfileCache::getInstance()->getUserProfile($this->userID); + } + else { + $this->userProfile = new UserProfile(new User(null, array( + 'username' => $this->username + ))); + } } return $this->userProfile; diff --git a/wcfsetup/install/files/lib/data/comment/ViewableCommentList.class.php b/wcfsetup/install/files/lib/data/comment/ViewableCommentList.class.php index af5c942d7a..89b8db4c54 100644 --- a/wcfsetup/install/files/lib/data/comment/ViewableCommentList.class.php +++ b/wcfsetup/install/files/lib/data/comment/ViewableCommentList.class.php @@ -1,5 +1,6 @@ sqlSelects)) $this->sqlSelects .= ','; - $this->sqlSelects .= "user_avatar.*, user_table.*"; - $this->sqlJoins .= " LEFT JOIN wcf".WCF_N."_user user_table ON (user_table.userID = comment.userID)"; - $this->sqlJoins .= " LEFT JOIN wcf".WCF_N."_user_avatar user_avatar ON (user_avatar.avatarID = user_table.avatarID)"; + if (!empty($this->objects)) { + $userIDs = array(); + foreach ($this->objects as $comment) { + if ($comment->userID) { + $userIDs[] = $comment->userID; + } + } + + if (!empty($userIDs)) { + UserProfileCache::getInstance()->cacheUserIDs($userIDs); + } + } } } diff --git a/wcfsetup/install/files/lib/data/comment/response/StructuredCommentResponse.class.php b/wcfsetup/install/files/lib/data/comment/response/StructuredCommentResponse.class.php index 8ac2e58ae9..9ead82e6fb 100644 --- a/wcfsetup/install/files/lib/data/comment/response/StructuredCommentResponse.class.php +++ b/wcfsetup/install/files/lib/data/comment/response/StructuredCommentResponse.class.php @@ -2,6 +2,7 @@ namespace wcf\data\comment\response; use wcf\data\user\User; use wcf\data\user\UserProfile; +use wcf\data\user\UserProfileCache; use wcf\data\DatabaseObjectDecorator; /** @@ -54,7 +55,14 @@ class StructuredCommentResponse extends DatabaseObjectDecorator { */ public function getUserProfile() { if ($this->userProfile === null) { - $this->userProfile = new UserProfile(new User(null, $this->data)); + if ($this->userID) { + $this->userProfile = UserProfileCache::getInstance()->getUserProfile($this->userID); + } + else { + $this->userProfile = new UserProfile(new User(null, array( + 'username' => $this->username + ))); + } } return $this->userProfile; @@ -75,9 +83,10 @@ class StructuredCommentResponse extends DatabaseObjectDecorator { // prepare structured response $response = new StructuredCommentResponse($response); - // add user profile - $userProfile = UserProfile::getUserProfile($response->userID); - $response->setUserProfile($userProfile); + // cache user profile + if ($response->userID) { + UserProfileCache::getInstance()->cacheUserID($response->userID); + } return $response; } diff --git a/wcfsetup/install/files/lib/data/comment/response/StructuredCommentResponseList.class.php b/wcfsetup/install/files/lib/data/comment/response/StructuredCommentResponseList.class.php index a8139a2ec6..67e02014bd 100644 --- a/wcfsetup/install/files/lib/data/comment/response/StructuredCommentResponseList.class.php +++ b/wcfsetup/install/files/lib/data/comment/response/StructuredCommentResponseList.class.php @@ -1,7 +1,7 @@ setIsEditable($this->commentManager->canEditResponse($response->getDecoratedObject())); } - // fetch user data and avatars + // cache user ids if (!empty($userIDs)) { - $userIDs = array_unique($userIDs); - - $users = UserProfile::getUserProfiles($userIDs); - foreach ($this->objects as $response) { - if (isset($users[$response->userID])) { - $response->setUserProfile($users[$response->userID]); - } - } + UserProfileCache::getInstance()->cacheUserIDs(array_unique($userIDs)); } } diff --git a/wcfsetup/install/files/lib/data/comment/response/ViewableCommentResponse.class.php b/wcfsetup/install/files/lib/data/comment/response/ViewableCommentResponse.class.php index a90ae1c953..63c88d99cc 100644 --- a/wcfsetup/install/files/lib/data/comment/response/ViewableCommentResponse.class.php +++ b/wcfsetup/install/files/lib/data/comment/response/ViewableCommentResponse.class.php @@ -2,7 +2,9 @@ namespace wcf\data\comment\response; use wcf\data\user\User; use wcf\data\user\UserProfile; +use wcf\data\user\UserProfileCache; use wcf\data\DatabaseObjectDecorator; +use wcf\data\TLegacyUserPropertyAccess; /** * Represents a viewable comment response. @@ -15,6 +17,8 @@ use wcf\data\DatabaseObjectDecorator; * @category Community Framework */ class ViewableCommentResponse extends DatabaseObjectDecorator { + use TLegacyUserPropertyAccess; + /** * @see \wcf\data\DatabaseObjectDecorator::$baseClass */ @@ -33,7 +37,14 @@ class ViewableCommentResponse extends DatabaseObjectDecorator { */ public function getUserProfile() { if ($this->userProfile === null) { - $this->userProfile = new UserProfile(new User(null, $this->getDecoratedObject()->data)); + if ($this->userID) { + $this->userProfile = UserProfileCache::getInstance()->getUserProfile($this->userID); + } + else { + $this->userProfile = new UserProfile(new User(null, array( + 'username' => $this->username + ))); + } } return $this->userProfile; diff --git a/wcfsetup/install/files/lib/data/comment/response/ViewableCommentResponseList.class.php b/wcfsetup/install/files/lib/data/comment/response/ViewableCommentResponseList.class.php index e39253be81..97b9f84548 100644 --- a/wcfsetup/install/files/lib/data/comment/response/ViewableCommentResponseList.class.php +++ b/wcfsetup/install/files/lib/data/comment/response/ViewableCommentResponseList.class.php @@ -1,5 +1,6 @@ sqlSelects)) $this->sqlSelects .= ','; - $this->sqlSelects .= "user_avatar.*, user_table.*"; - $this->sqlJoins .= " LEFT JOIN wcf".WCF_N."_user user_table ON (user_table.userID = comment_response.userID)"; - $this->sqlJoins .= " LEFT JOIN wcf".WCF_N."_user_avatar user_avatar ON (user_avatar.avatarID = user_table.avatarID)"; + public function readObjects() { + parent::readObjects(); + + if (!empty($this->objects)) { + $userIDs = array(); + foreach ($this->objects as $response) { + if ($response->userID) { + $userIDs[] = $response->userID; + } + } + + if (!empty($userIDs)) { + UserProfileCache::getInstance()->cacheUserIDs($userIDs); + } + } } } diff --git a/wcfsetup/install/files/lib/data/like/ViewableLike.class.php b/wcfsetup/install/files/lib/data/like/ViewableLike.class.php index 1400e8b1e8..4c860373d0 100644 --- a/wcfsetup/install/files/lib/data/like/ViewableLike.class.php +++ b/wcfsetup/install/files/lib/data/like/ViewableLike.class.php @@ -2,6 +2,7 @@ namespace wcf\data\like; use wcf\data\object\type\ObjectTypeCache; use wcf\data\user\UserProfile; +use wcf\data\user\UserProfileCache; use wcf\data\DatabaseObjectDecorator; /** @@ -75,6 +76,10 @@ class ViewableLike extends DatabaseObjectDecorator { * @return \wcf\data\user\UserProfile */ public function getUserProfile() { + if ($this->userProfile === null) { + $this->userProfile = UserProfileCache::getInstance()->getUserProfile($this->userID); + } + return $this->userProfile; } diff --git a/wcfsetup/install/files/lib/data/like/ViewableLikeList.class.php b/wcfsetup/install/files/lib/data/like/ViewableLikeList.class.php index 9199d3178f..21e15489e9 100644 --- a/wcfsetup/install/files/lib/data/like/ViewableLikeList.class.php +++ b/wcfsetup/install/files/lib/data/like/ViewableLikeList.class.php @@ -1,7 +1,7 @@ objects as $like) { - $like->setUserProfile($users[$like->userID]); - } + UserProfileCache::getInstance()->cacheUserIDs(array_unique($userIDs)); } // parse like diff --git a/wcfsetup/install/files/lib/data/moderation/queue/ViewableModerationQueue.class.php b/wcfsetup/install/files/lib/data/moderation/queue/ViewableModerationQueue.class.php index 3b1566cba9..a98ea64453 100644 --- a/wcfsetup/install/files/lib/data/moderation/queue/ViewableModerationQueue.class.php +++ b/wcfsetup/install/files/lib/data/moderation/queue/ViewableModerationQueue.class.php @@ -3,6 +3,7 @@ namespace wcf\data\moderation\queue; use wcf\data\object\type\ObjectTypeCache; use wcf\data\user\User; use wcf\data\user\UserProfile; +use wcf\data\user\UserProfileCache; use wcf\data\DatabaseObjectDecorator; use wcf\data\IUserContent; use wcf\system\moderation\queue\ModerationQueueManager; @@ -97,7 +98,7 @@ class ViewableModerationQueue extends DatabaseObjectDecorator { public function getUserProfile() { if ($this->affectedObject !== null && $this->userProfile === null) { if ($this->affectedObject->getUserID()) { - $this->userProfile = UserProfile::getUserProfile($this->affectedObject->getUserID()); + $this->userProfile = UserProfileCache::getInstance()->getUserProfile($this->affectedObject->getUserID()); } else { $this->userProfile = new UserProfile(new User(null, array())); diff --git a/wcfsetup/install/files/lib/data/moderation/queue/ViewableModerationQueueList.class.php b/wcfsetup/install/files/lib/data/moderation/queue/ViewableModerationQueueList.class.php index 1ddd7061af..7c6d6556a1 100644 --- a/wcfsetup/install/files/lib/data/moderation/queue/ViewableModerationQueueList.class.php +++ b/wcfsetup/install/files/lib/data/moderation/queue/ViewableModerationQueueList.class.php @@ -1,6 +1,6 @@ getAffectedObject()->getUserID(); } - $userProfiles = UserProfile::getUserProfiles($userIDs); - foreach ($this->objects as $object) { - if (isset($userProfiles[$object->getAffectedObject()->getUserID()])) { - $object->setUserProfile($userProfiles[$object->getAffectedObject()->getUserID()]); - } - } + UserProfileCache::getInstance()->cacheUserIDs(array_unique($userIDs)); } } } diff --git a/wcfsetup/install/files/lib/data/user/UserProfile.class.php b/wcfsetup/install/files/lib/data/user/UserProfile.class.php index ec2078e1cb..aa2129da4e 100644 --- a/wcfsetup/install/files/lib/data/user/UserProfile.class.php +++ b/wcfsetup/install/files/lib/data/user/UserProfile.class.php @@ -342,11 +342,10 @@ class UserProfile extends DatabaseObjectDecorator implements IBreadcrumbProvider * * @param integer $userID * @return \wcf\data\user\UserProfile + * @deprecated use UserProfileCache::getUserProfile() */ public static function getUserProfile($userID) { - $users = self::getUserProfiles(array($userID)); - - return (isset($users[$userID]) ? $users[$userID] : null); + return UserProfileCache::getInstance()->getUserProfile($userID); } /** @@ -354,26 +353,15 @@ class UserProfile extends DatabaseObjectDecorator implements IBreadcrumbProvider * * @param array $userIDs * @return array<\wcf\data\user\UserProfile> + * @deprecated use UserProfileCache::getUserProfiles() */ public static function getUserProfiles(array $userIDs) { - $users = array(); - - // check cache - foreach ($userIDs as $index => $userID) { - if (isset(self::$userProfiles[$userID])) { - $users[$userID] = self::$userProfiles[$userID]; - unset($userIDs[$index]); - } - } + $users = UserProfileCache::getInstance()->getUserProfiles($userIDs); - if (!empty($userIDs)) { - $userList = new UserProfileList(); - $userList->setObjectIDs($userIDs); - $userList->readObjects(); - - foreach ($userList as $user) { - $users[$user->userID] = $user; - self::$userProfiles[$user->userID] = $user; + // this method does not return null for non-existing user profiles + foreach ($users as $userID => $user) { + if ($user === null) { + unset($users[$userID]); } } @@ -385,6 +373,7 @@ class UserProfile extends DatabaseObjectDecorator implements IBreadcrumbProvider * * @param string $username * @return \wcf\data\user\UserProfile + * @todo move to UserProfileCache? */ public static function getUserProfileByUsername($username) { $users = self::getUserProfilesByUsername(array($username)); @@ -397,6 +386,7 @@ class UserProfile extends DatabaseObjectDecorator implements IBreadcrumbProvider * * @param array $usernames * @return array<\wcf\data\user\UserProfile> + * @todo move to UserProfileCache? */ public static function getUserProfilesByUsername(array $usernames) { $users = array(); @@ -411,8 +401,9 @@ class UserProfile extends DatabaseObjectDecorator implements IBreadcrumbProvider unset($username); // check cache + $userProfiles = UserProfileCache::getInstance()->getCachedUserProfiles(); foreach ($usernames as $index => $username) { - foreach (self::$userProfiles as $user) { + foreach ($userProfiles as $user) { if (mb_strtolower($user->username) === $username) { $users[$username] = $user; unset($usernames[$index]); diff --git a/wcfsetup/install/files/lib/data/user/UserProfileCache.class.php b/wcfsetup/install/files/lib/data/user/UserProfileCache.class.php new file mode 100644 index 0000000000..3067768fa4 --- /dev/null +++ b/wcfsetup/install/files/lib/data/user/UserProfileCache.class.php @@ -0,0 +1,115 @@ + + * @package com.woltlab.wcf + * @subpackage data.user + * @category Community Framework + */ +class UserProfileCache extends SingletonFactory { + /** + * cached user ids whose profiles will be loaded during the next request + * @var array + */ + protected $userIDs = array(); + + /** + * locally cached user profiles + * @var array<\wcf\data\user\UserProfile> + */ + protected $userProfiles = array(); + + /** + * Caches the given user id. + * + * @param integer $userID + */ + public function cacheUserID($userID) { + $this->userIDs[] = $userID; + } + + /** + * Caches the given user ids. + * + * @param array $userID + */ + public function cacheUserIDs(array $userIDs) { + $this->userIDs = array_merge($this->userIDs, $userIDs); + } + + /** + * Returns all currently cached user profile objects. + * + * @return array<\wcf\data\user\UserProfile> + */ + public function getCachedUserProfiles() { + return $this->userProfiles; + } + + /** + * Returns the user profile of the user with the given user id. If no such + * user profile exists, null is returned. + * + * @param integer $userID + * @return \wcf\data\user\UserProfile + */ + public function getUserProfile($userID) { + if (array_key_exists($userID, $this->userProfiles)) { + return $this->userProfiles[$userID]; + } + + return $this->getUserProfiles(array($userID))[$userID]; + } + + /** + * Returns the user profiles of the users with the given user ids. For ids + * without a user profile, null is returned. + * + * @param array $userIDs + * @return array<\wcf\data\user\UserProfile> + */ + public function getUserProfiles(array $userIDs) { + $userProfiles = array(); + foreach ($userIDs as $key => $userID) { + if (array_key_exists($userID, $this->userProfiles)) { + $userProfiles[$userID] = $this->userProfiles[$userID]; + + unset($userIDs[$key]); + } + } + + if (empty($userIDs)) { + return $userProfiles; + } + + $this->userIDs = array_unique(array_merge($this->userIDs, $userIDs)); + + $userProfileList = new UserProfileList(); + $userProfileList->setObjectIDs($this->userIDs); + $userProfileList->readObjects(); + $readUserProfiles = $userProfileList->getObjects(); + + foreach ($this->userIDs as $userID) { + if (!isset($readUserProfiles[$userID])) { + $this->userProfiles[$userID] = null; + } + else { + $this->userProfiles[$userID] = $readUserProfiles[$userID]; + } + } + + $this->userIDs = array(); + + foreach ($userIDs as $userID) { + $userProfiles[$userID] = $this->userProfiles[$userID]; + } + + return $userProfiles; + } +} diff --git a/wcfsetup/install/files/lib/data/user/activity/event/ViewableUserActivityEvent.class.php b/wcfsetup/install/files/lib/data/user/activity/event/ViewableUserActivityEvent.class.php index a7e41ff778..19e6736ba0 100644 --- a/wcfsetup/install/files/lib/data/user/activity/event/ViewableUserActivityEvent.class.php +++ b/wcfsetup/install/files/lib/data/user/activity/event/ViewableUserActivityEvent.class.php @@ -1,6 +1,7 @@ userProfile === null) { + $this->userProfile = UserProfileCache::getInstance()->getUserProfile($this->userID); + } + return $this->userProfile; } diff --git a/wcfsetup/install/files/lib/data/user/activity/event/ViewableUserActivityEventList.class.php b/wcfsetup/install/files/lib/data/user/activity/event/ViewableUserActivityEventList.class.php index 1455c716f7..afdb5f3b38 100644 --- a/wcfsetup/install/files/lib/data/user/activity/event/ViewableUserActivityEventList.class.php +++ b/wcfsetup/install/files/lib/data/user/activity/event/ViewableUserActivityEventList.class.php @@ -1,6 +1,6 @@ objects as $event) { - $event->setUserProfile($users[$event->userID]); - } + UserProfileCache::getInstance()->cacheUserIDs(array_unique($userIDs)); } // parse events diff --git a/wcfsetup/install/files/lib/system/dashboard/box/MostActiveMembersDashboardBox.class.php b/wcfsetup/install/files/lib/system/dashboard/box/MostActiveMembersDashboardBox.class.php index 568125ad51..50895a1af3 100644 --- a/wcfsetup/install/files/lib/system/dashboard/box/MostActiveMembersDashboardBox.class.php +++ b/wcfsetup/install/files/lib/system/dashboard/box/MostActiveMembersDashboardBox.class.php @@ -1,7 +1,8 @@ */ - public $userProfileList = null; + public $mostActiveMemberIDs = array(); /** * @see \wcf\system\dashboard\box\AbstractDashboardBoxContent::init() @@ -31,13 +32,9 @@ class MostActiveMembersDashboardBox extends AbstractSidebarDashboardBox { parent::init($box, $page); // get ids - $mostActiveMemberIDs = MostActiveMembersCacheBuilder::getInstance()->getData(); - if (!empty($mostActiveMemberIDs)) { - // get profile data - $this->userProfileList = new UserProfileList(); - $this->userProfileList->sqlOrderBy = 'user_table.activityPoints DESC'; - $this->userProfileList->setObjectIDs($mostActiveMemberIDs); - $this->userProfileList->readObjects(); + $this->mostActiveMemberIDs = MostActiveMembersCacheBuilder::getInstance()->getData(); + if (!empty($this->mostActiveMemberIDs)) { + UserProfileCache::getInstance()->cacheUserIDs($this->mostActiveMemberIDs); } $this->fetched(); @@ -47,13 +44,17 @@ class MostActiveMembersDashboardBox extends AbstractSidebarDashboardBox { * @see \wcf\system\dashboard\box\AbstractContentDashboardBox::render() */ protected function render() { - if ($this->userProfileList == null) return ''; + if (empty($this->mostActiveMemberIDs)) return ''; if (MODULE_MEMBERS_LIST) { $this->titleLink = LinkHandler::getInstance()->getLink('MembersList', array(), 'sortField=activityPoints&sortOrder=DESC'); } + + $mostActiveMembers = UserProfileCache::getInstance()->getUserProfiles($this->mostActiveMemberIDs); + DatabaseObject::sort($mostActiveMembers, 'activityPoints', 'DESC'); + WCF::getTPL()->assign(array( - 'mostActiveMembers' => $this->userProfileList + 'mostActiveMembers' => $mostActiveMembers )); return WCF::getTPL()->fetch('dashboardBoxMostActiveMembers'); } diff --git a/wcfsetup/install/files/lib/system/dashboard/box/MostLikedMembersDashboardBox.class.php b/wcfsetup/install/files/lib/system/dashboard/box/MostLikedMembersDashboardBox.class.php index 2c1e1f3a72..fa80d6ad91 100644 --- a/wcfsetup/install/files/lib/system/dashboard/box/MostLikedMembersDashboardBox.class.php +++ b/wcfsetup/install/files/lib/system/dashboard/box/MostLikedMembersDashboardBox.class.php @@ -1,7 +1,8 @@ */ - public $userProfileList = null; + public $mostLikedMemberIDs = array(); /** * @see \wcf\system\dashboard\box\IDashboardBox::init() @@ -31,29 +32,30 @@ class MostLikedMembersDashboardBox extends AbstractSidebarDashboardBox { parent::init($box, $page); // get ids - $mostLikedMemberIDs = MostLikedMembersCacheBuilder::getInstance()->getData(); - if (!empty($mostLikedMemberIDs)) { - // get profile data - $this->userProfileList = new UserProfileList(); - $this->userProfileList->sqlOrderBy = 'user_table.likesReceived DESC'; - $this->userProfileList->setObjectIDs($mostLikedMemberIDs); - $this->userProfileList->readObjects(); - } + $this->mostLikedMemberIDs = MostLikedMembersCacheBuilder::getInstance()->getData(); $this->fetched(); + + if (!empty($this->mostLikedMemberIDs)) { + UserProfileCache::getInstance()->cacheUserIDs($this->mostLikedMemberIDs); + } } /** * @see \wcf\system\dashboard\box\AbstractContentDashboardBox::render() */ protected function render() { - if ($this->userProfileList == null) return ''; + if (empty($this->mostLikedMemberIDs)) return ''; if (MODULE_MEMBERS_LIST) { $this->titleLink = LinkHandler::getInstance()->getLink('MembersList', array(), 'sortField=likesReceived&sortOrder=DESC'); } + + $mostLikedMembers = UserProfileCache::getInstance()->getUserProfiles($this->mostLikedMemberIDs); + DatabaseObject::sort($mostLikedMembers, 'likesReceived', 'DESC'); + WCF::getTPL()->assign(array( - 'mostLikedMembers' => $this->userProfileList + 'mostLikedMembers' => $mostLikedMembers )); return WCF::getTPL()->fetch('dashboardBoxMostLikedMembers'); } diff --git a/wcfsetup/install/files/lib/system/dashboard/box/NewestMembersDashboardBox.class.php b/wcfsetup/install/files/lib/system/dashboard/box/NewestMembersDashboardBox.class.php index 4fe5e00ee3..2d807c3525 100644 --- a/wcfsetup/install/files/lib/system/dashboard/box/NewestMembersDashboardBox.class.php +++ b/wcfsetup/install/files/lib/system/dashboard/box/NewestMembersDashboardBox.class.php @@ -1,7 +1,8 @@ */ - public $userProfileList = null; + public $newestMemberIDs = array(); /** * @see \wcf\system\dashboard\box\IDashboardBox::init() @@ -31,13 +32,9 @@ class NewestMembersDashboardBox extends AbstractSidebarDashboardBox { parent::init($box, $page); // get ids - $newestMemberIDs = NewestMembersCacheBuilder::getInstance()->getData(); - if (!empty($newestMemberIDs)) { - // get profile data - $this->userProfileList = new UserProfileList(); - $this->userProfileList->sqlOrderBy = 'user_table.registrationDate DESC'; - $this->userProfileList->setObjectIDs($newestMemberIDs); - $this->userProfileList->readObjects(); + $this->newestMemberIDs = NewestMembersCacheBuilder::getInstance()->getData(); + if (!empty($this->newestMemberIDs)) { + UserProfileCache::getInstance()->cacheUserIDs($this->newestMemberIDs); } $this->fetched(); @@ -47,13 +44,17 @@ class NewestMembersDashboardBox extends AbstractSidebarDashboardBox { * @see \wcf\system\dashboard\box\AbstractContentDashboardBox::render() */ protected function render() { - if ($this->userProfileList == null) return ''; + if (empty($this->newestMemberIDs)) return ''; if (MODULE_MEMBERS_LIST) { $this->titleLink = LinkHandler::getInstance()->getLink('MembersList', array(), 'sortField=registrationDate&sortOrder=DESC'); } + + $newestMembers = UserProfileCache::getInstance()->getUserProfiles($this->newestMemberIDs); + DatabaseObject::sort($newestMembers, 'registrationDate', 'DESC'); + WCF::getTPL()->assign(array( - 'newestMembers' => $this->userProfileList + 'newestMembers' => $newestMembers )); return WCF::getTPL()->fetch('dashboardBoxNewestMembers'); } diff --git a/wcfsetup/install/files/lib/system/dashboard/box/TodaysBirthdaysDashboardBox.class.php b/wcfsetup/install/files/lib/system/dashboard/box/TodaysBirthdaysDashboardBox.class.php index fa1ae27e2a..3b6976e5b6 100644 --- a/wcfsetup/install/files/lib/system/dashboard/box/TodaysBirthdaysDashboardBox.class.php +++ b/wcfsetup/install/files/lib/system/dashboard/box/TodaysBirthdaysDashboardBox.class.php @@ -1,7 +1,7 @@ setObjectIDs($userIDs); - $userProfileList->readObjects(); + $userProfiles = UserProfileCache::getInstance()->getUserProfiles($userIDs); + $i = 0; - foreach ($userProfileList as $userProfile) { + foreach ($userProfiles as $userProfile) { if ($i == 10) break; $birthdayUserOption->setUser($userProfile->getDecoratedObject()); - + if (!$userProfile->isProtected() && $birthdayUserOption->isVisible() && substr($userProfile->birthday, 5) == $currentDay) { $this->userProfiles[] = $userProfile; $i++; diff --git a/wcfsetup/install/files/lib/system/dashboard/box/TodaysFollowingBirthdaysDashboardBox.class.php b/wcfsetup/install/files/lib/system/dashboard/box/TodaysFollowingBirthdaysDashboardBox.class.php index 8e249afac7..8f3640f1bd 100644 --- a/wcfsetup/install/files/lib/system/dashboard/box/TodaysFollowingBirthdaysDashboardBox.class.php +++ b/wcfsetup/install/files/lib/system/dashboard/box/TodaysFollowingBirthdaysDashboardBox.class.php @@ -1,7 +1,7 @@ getFollowingUsers()); if (!empty($userIDs)) { - $userProfileList = new UserProfileList(); - $userProfileList->setObjectIDs($userIDs); - $userProfileList->readObjects(); + $userProfiles = UserProfileCache::getInstance()->getUserProfiles($userIDs); + $i = 0; - foreach ($userProfileList as $userProfile) { + foreach ($userProfiles as $userProfile) { if ($i == 10) break; if (!$userProfile->isProtected() && substr($userProfile->birthday, 5) == $currentDay) { diff --git a/wcfsetup/install/files/lib/system/message/embedded/object/QuoteMessageEmbeddedObjectHandler.class.php b/wcfsetup/install/files/lib/system/message/embedded/object/QuoteMessageEmbeddedObjectHandler.class.php index f65135fcef..ce7d2d7ff2 100644 --- a/wcfsetup/install/files/lib/system/message/embedded/object/QuoteMessageEmbeddedObjectHandler.class.php +++ b/wcfsetup/install/files/lib/system/message/embedded/object/QuoteMessageEmbeddedObjectHandler.class.php @@ -1,7 +1,7 @@ getUserProfiles($objectIDs); } } diff --git a/wcfsetup/install/files/lib/system/user/activity/event/ProfileCommentResponseUserActivityEvent.class.php b/wcfsetup/install/files/lib/system/user/activity/event/ProfileCommentResponseUserActivityEvent.class.php index a9a58be223..b3687c7ede 100644 --- a/wcfsetup/install/files/lib/system/user/activity/event/ProfileCommentResponseUserActivityEvent.class.php +++ b/wcfsetup/install/files/lib/system/user/activity/event/ProfileCommentResponseUserActivityEvent.class.php @@ -2,7 +2,7 @@ namespace wcf\system\user\activity\event; use wcf\data\comment\response\CommentResponseList; use wcf\data\comment\CommentList; -use wcf\data\user\UserProfileList; +use wcf\data\user\UserProfileCache; use wcf\system\user\activity\event\IUserActivityEvent; use wcf\system\SingletonFactory; use wcf\system\WCF; @@ -56,10 +56,7 @@ class ProfileCommentResponseUserActivityEvent extends SingletonFactory implement $userIDs[] = $comment->userID; } if (!empty($userIDs)) { - $userList = new UserProfileList(); - $userList->setObjectIDs($userIDs); - $userList->readObjects(); - $users = $userList->getObjects(); + $users = UserProfileCache::getInstance()->getUserProfiles($userIDs); } // set message diff --git a/wcfsetup/install/files/lib/system/user/activity/event/ProfileCommentUserActivityEvent.class.php b/wcfsetup/install/files/lib/system/user/activity/event/ProfileCommentUserActivityEvent.class.php index 068e439a2b..47f4663076 100644 --- a/wcfsetup/install/files/lib/system/user/activity/event/ProfileCommentUserActivityEvent.class.php +++ b/wcfsetup/install/files/lib/system/user/activity/event/ProfileCommentUserActivityEvent.class.php @@ -1,7 +1,7 @@ objectID; } if (!empty($userIDs)) { - $userList = new UserProfileList(); - $userList->setObjectIDs($userIDs); - $userList->readObjects(); - $users = $userList->getObjects(); + $users = UserProfileCache::getInstance()->getUserProfiles($userIDs); } // set message