From: Matthias Schmidt Date: Sat, 8 Aug 2015 10:27:29 +0000 (+0200) Subject: Use UserProfileCache X-Git-Tag: 3.0.0_Beta_1~170 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=30901bc2df661a8dcfc0a2b0c23e6c0af6fc92fd;p=GitHub%2FWoltLab%2Fcom.woltlab.wcf.conversation.git Use UserProfileCache --- diff --git a/files/lib/data/conversation/UserConversationList.class.php b/files/lib/data/conversation/UserConversationList.class.php index f1e502a..d93e76a 100644 --- a/files/lib/data/conversation/UserConversationList.class.php +++ b/files/lib/data/conversation/UserConversationList.class.php @@ -2,6 +2,7 @@ namespace wcf\data\conversation; use wcf\data\conversation\label\ConversationLabel; use wcf\data\conversation\label\ConversationLabelList; +use wcf\data\user\UserProfileCache; use wcf\system\database\util\PreparedStatementConditionBuilder; use wcf\system\WCF; @@ -80,18 +81,6 @@ class UserConversationList extends ConversationList { if (!empty($this->sqlSelects)) $this->sqlSelects .= ','; $this->sqlSelects .= "conversation_to_user.*"; $this->sqlJoins .= "LEFT JOIN wcf".WCF_N."_conversation_to_user conversation_to_user ON (conversation_to_user.participantID = ".$userID." AND conversation_to_user.conversationID = conversation.conversationID)"; - - // get avatars - if (!empty($this->sqlSelects)) $this->sqlSelects .= ','; - $this->sqlSelects .= "user_avatar.*, user_table.email, user_table.disableAvatar, user_table.enableGravatar, user_table.gravatarFileExtension"; - $this->sqlJoins .= " LEFT JOIN wcf".WCF_N."_user user_table ON (user_table.userID = conversation.userID)"; - $this->sqlJoins .= " LEFT JOIN wcf".WCF_N."_user_avatar user_avatar ON (user_avatar.avatarID = user_table.avatarID)"; - - if (!empty($this->sqlSelects)) $this->sqlSelects .= ','; - $this->sqlSelects .= "lastposter_avatar.avatarID AS lastPosterAvatarID, lastposter_avatar.avatarName AS lastPosterAvatarName, lastposter_avatar.avatarExtension AS lastPosterAvatarExtension, lastposter_avatar.width AS lastPosterAvatarWidth, lastposter_avatar.height AS lastPosterAvatarHeight,"; - $this->sqlSelects .= "lastposter.email AS lastPosterEmail, lastposter.disableAvatar AS lastPosterDisableAvatar, lastposter.enableGravatar AS lastPosterEnableGravatar, lastposter.gravatarFileExtension AS lastPosterGravatarFileExtension"; - $this->sqlJoins .= " LEFT JOIN wcf".WCF_N."_user lastposter ON (lastposter.userID = conversation.lastPosterID)"; - $this->sqlJoins .= " LEFT JOIN wcf".WCF_N."_user_avatar lastposter_avatar ON (lastposter_avatar.avatarID = lastposter.avatarID)"; } /** @@ -151,12 +140,24 @@ class UserConversationList extends ConversationList { if (!empty($this->objects)) { $labels = $this->loadLabelAssignments(); + $userIDs = [ ]; foreach ($this->objects as $conversationID => $conversation) { if (isset($labels[$conversationID])) { foreach ($labels[$conversationID] as $label) { $conversation->assignLabel($label); } } + + if ($conversation->userID) { + $userIDs[] = $conversation->userID; + } + if ($conversation->lastPosterID) { + $userIDs[] = $conversation->lastPosterID; + } + } + + if (!empty($userIDs)) { + UserProfileCache::getInstance()->cacheUserIDs($userIDs); } } } diff --git a/files/lib/data/conversation/ViewableConversation.class.php b/files/lib/data/conversation/ViewableConversation.class.php index d7f4a05..caa3015 100644 --- a/files/lib/data/conversation/ViewableConversation.class.php +++ b/files/lib/data/conversation/ViewableConversation.class.php @@ -4,7 +4,9 @@ use wcf\data\conversation\label\ConversationLabel; use wcf\data\conversation\label\ConversationLabelList; use wcf\data\user\User; use wcf\data\user\UserProfile; +use wcf\data\user\UserProfileCache; use wcf\data\DatabaseObjectDecorator; +use wcf\data\TLegacyUserPropertyAccess; use wcf\system\database\util\PreparedStatementConditionBuilder; use wcf\system\WCF; @@ -19,6 +21,8 @@ use wcf\system\WCF; * @category Community Framework */ class ViewableConversation extends DatabaseObjectDecorator { + use TLegacyUserPropertyAccess; + /** * participant summary * @var string @@ -37,16 +41,60 @@ class ViewableConversation extends DatabaseObjectDecorator { */ protected $lastPosterProfile = null; + /** + * list of assigned labels + * @var array<\wcf\data\conversation\label\ConversationLabel> + */ + protected $labels = array(); + /** * @see \wcf\data\DatabaseObjectDecorator::$baseClass */ protected static $baseClass = 'wcf\data\conversation\Conversation'; /** - * list of assigned labels - * @var array<\wcf\data\conversation\label\ConversationLabel> + * maps legacy direct access to last poster's user profile data to the real + * user profile property names + * @var array + * @deprecated */ - protected $labels = array(); + protected static $__lastUserAvatarPropertyMapping = array( + 'lastPosterAvatarID' => 'avatarID', + 'lastPosterAvatarName' => 'avatarName', + 'lastPosterAvatarExtension' => 'avatarExtension', + 'lastPosterAvatarWidth' => 'width', + 'lastPosterAvatarHeight' => 'height', + 'lastPosterEmail' => 'email', + 'lastPosterDisableAvatar' => 'disableAvatar', + 'lastPosterEnableGravatar' => 'enableGravatar', + 'lastPosterGravatarFileExtension' => 'gravatarFileExtension', + 'lastPosterAvatarFileHash' => 'fileHash' + ); + + /** + * @see \wcf\data\IStorableObject::__get() + * @deprecated + */ + public function __get($name) { + $value = parent::__get($name); + if ($value !== null) { + return $value; + } + else if (array_key_exists($name, $this->object->data)) { + return null; + } + + $value = $this->getUserProfile()->$name; + if ($value !== null) { + return $value; + } + + if (isset(static::$__lastUserAvatarPropertyMapping[$name])) { + return $this->getLastPosterProfile()->getAvatar()->{static::$__lastUserAvatarPropertyMapping[$name]}; + } + + return null; + } /** * Returns the user profile object. @@ -55,7 +103,14 @@ class ViewableConversation 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; @@ -68,22 +123,12 @@ class ViewableConversation extends DatabaseObjectDecorator { */ public function getLastPosterProfile() { if ($this->lastPosterProfile === null) { - if ($this->userID && $this->userID == $this->lastPosterID) { - $this->lastPosterProfile = $this->getUserProfile(); + if ($this->lastPosterID) { + $this->lastPosterProfile = UserProfileCache::getInstance()->getUserProfile($this->lastPosterID); } else { $this->lastPosterProfile = new UserProfile(new User(null, array( - 'userID' => $this->lastPosterID, - 'username' => $this->lastPoster, - 'avatarID' => $this->lastPosterAvatarID, - 'avatarName' => $this->lastPosterAvatarName, - 'avatarExtension' => $this->lastPosterAvatarExtension, - 'width' => $this->lastPosterAvatarWidth, - 'height' => $this->lastPosterAvatarHeight, - 'email' => $this->lastPosterEmail, - 'disableAvatar' => $this->lastPosterDisableAvatar, - 'enableGravatar' => $this->lastPosterEnableGravatar, - 'gravatarFileExtension' => $this->lastPosterGravatarFileExtension + 'username' => $this->lastPoster ))); } } diff --git a/files/lib/data/conversation/message/ViewableConversationMessage.class.php b/files/lib/data/conversation/message/ViewableConversationMessage.class.php index f9fc01d..5e6056f 100644 --- a/files/lib/data/conversation/message/ViewableConversationMessage.class.php +++ b/files/lib/data/conversation/message/ViewableConversationMessage.class.php @@ -2,7 +2,9 @@ namespace wcf\data\conversation\message; 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 conversation message. @@ -15,6 +17,8 @@ use wcf\data\DatabaseObjectDecorator; * @category Community Framework */ class ViewableConversationMessage extends DatabaseObjectDecorator { + use TLegacyUserPropertyAccess; + /** * @see \wcf\data\DatabaseObjectDecorator::$baseClass */ @@ -33,7 +37,14 @@ class ViewableConversationMessage 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/files/lib/data/conversation/message/ViewableConversationMessageList.class.php b/files/lib/data/conversation/message/ViewableConversationMessageList.class.php index 6ac77cd..30b82d4 100644 --- a/files/lib/data/conversation/message/ViewableConversationMessageList.class.php +++ b/files/lib/data/conversation/message/ViewableConversationMessageList.class.php @@ -3,6 +3,7 @@ namespace wcf\data\conversation\message; use wcf\data\attachment\GroupedAttachmentList; use wcf\data\conversation\Conversation; use wcf\data\object\type\ObjectTypeCache; +use wcf\data\user\UserProfileCache; use wcf\system\message\embedded\object\MessageEmbeddedObjectManager; /** @@ -68,22 +69,6 @@ class ViewableConversationMessageList extends ConversationMessageList { */ protected $conversation = null; - /** - * Creates a new ViewableConversationMessageList object. - */ - public function __construct() { - parent::__construct(); - - $this->sqlSelects .= "user_option_value.*, user_table.*"; - $this->sqlJoins .= " LEFT JOIN wcf".WCF_N."_user user_table ON (user_table.userID = conversation_message.userID)"; - $this->sqlJoins .= " LEFT JOIN wcf".WCF_N."_user_option_value user_option_value ON (user_option_value.userID = user_table.userID)"; - - // get avatars - if (!empty($this->sqlSelects)) $this->sqlSelects .= ','; - $this->sqlSelects .= "user_avatar.*"; - $this->sqlJoins .= " LEFT JOIN wcf".WCF_N."_user_avatar user_avatar ON (user_avatar.avatarID = user_table.avatarID)"; - } - /** * @see \wcf\data\DatabaseObjectList::readObjects() */ @@ -94,6 +79,7 @@ class ViewableConversationMessageList extends ConversationMessageList { parent::readObjects(); + $userIDs = [ ]; foreach ($this->objects as $message) { if ($message->time > $this->maxPostTime) { $this->maxPostTime = $message->time; @@ -109,6 +95,13 @@ class ViewableConversationMessageList extends ConversationMessageList { if ($message->hasEmbeddedObjects) { $this->embeddedObjectMessageIDs[] = $message->messageID; } + if ($message->userID) { + $userIDs[] = $message->userID; + } + } + + if (!empty($userIDs)) { + UserProfileCache::getInstance()->cacheUserIDs($userIDs); } if ($this->embeddedObjectLoading) { @@ -126,7 +119,7 @@ class ViewableConversationMessageList extends ConversationMessageList { if (!empty($this->embeddedObjectMessageIDs)) { // add message objects to attachment object cache to save SQL queries ObjectTypeCache::getInstance()->getObjectTypeByName('com.woltlab.wcf.attachment.objectType', 'com.woltlab.wcf.conversation.message')->getProcessor()->setCachedObjects($this->objects); - + // load embedded objects MessageEmbeddedObjectManager::getInstance()->loadObjects('com.woltlab.wcf.conversation.message', $this->embeddedObjectMessageIDs); } diff --git a/files/lib/data/modification/log/ConversationLogModificationLogList.class.php b/files/lib/data/modification/log/ConversationLogModificationLogList.class.php index f9e1529..0b9f9b4 100644 --- a/files/lib/data/modification/log/ConversationLogModificationLogList.class.php +++ b/files/lib/data/modification/log/ConversationLogModificationLogList.class.php @@ -1,6 +1,7 @@ sqlOrderBy) ? "ORDER BY ".$this->sqlOrderBy : ''); + $sql = "SELECT modification_log.* + FROM wcf".WCF_N."_modification_log modification_log + WHERE modification_log.objectTypeID = ? + AND modification_log.objectID = ? + ".(!empty($this->sqlOrderBy) ? "ORDER BY ".$this->sqlOrderBy : ''); $statement = WCF::getDB()->prepareStatement($sql, $this->sqlLimit, $this->sqlOffset); $statement->execute(array( $this->conversationObjectTypeID, @@ -86,16 +83,24 @@ class ConversationLogModificationLogList extends ModificationLogList { $this->objects = $statement->fetchObjects(($this->objectClassName ?: $this->className)); // use table index as array index - $objects = array(); + $objects = $userIDs = [ ]; foreach ($this->objects as $object) { $objectID = $object->{$this->getDatabaseTableIndexName()}; $objects[$objectID] = $object; $this->indexToObject[] = $objectID; + + if ($object->userID) { + $userIDs[] = $object->userID; + } } $this->objectIDs = $this->indexToObject; $this->objects = $objects; + if (!empty($userIDs)) { + UserProfileCache::getInstance()->cacheUserIDs($userIDs); + } + foreach ($this->objects as &$object) { $object = new ViewableConversationModificationLog($object); } diff --git a/files/lib/data/modification/log/ViewableConversationModificationLog.class.php b/files/lib/data/modification/log/ViewableConversationModificationLog.class.php index e738625..d7f246c 100644 --- a/files/lib/data/modification/log/ViewableConversationModificationLog.class.php +++ b/files/lib/data/modification/log/ViewableConversationModificationLog.class.php @@ -2,7 +2,9 @@ namespace wcf\data\modification\log; use wcf\data\user\User; use wcf\data\user\UserProfile; +use wcf\data\user\UserProfileCache; use wcf\data\DatabaseObjectDecorator; +use wcf\data\TLegacyUserPropertyAccess; use wcf\system\WCF; /** @@ -16,6 +18,8 @@ use wcf\system\WCF; * @category Community Framework */ class ViewableConversationModificationLog extends DatabaseObjectDecorator { + use TLegacyUserPropertyAccess; + /** * @see \wcf\data\DatabaseObjectDecorator::$baseClass */ @@ -41,7 +45,14 @@ class ViewableConversationModificationLog 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;