From 7a1b2331896918a4a4e05bba272d119fe38a8dbb Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Wed, 9 May 2018 15:06:49 +0200 Subject: [PATCH] Improved the performance of the check for ignoring users Fixes #2566 --- .../templates/userInformationButtons.tpl | 2 +- .../files/lib/data/user/UserProfile.class.php | 52 ++++++++++++++++++- .../user/ignore/UserIgnoreAction.class.php | 1 + 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/com.woltlab.wcf/templates/userInformationButtons.tpl b/com.woltlab.wcf/templates/userInformationButtons.tpl index 6836711d12..ca3941c10a 100644 --- a/com.woltlab.wcf/templates/userInformationButtons.tpl +++ b/com.woltlab.wcf/templates/userInformationButtons.tpl @@ -15,7 +15,7 @@ {/if} {if $__wcf->user->userID && $user->userID != $__wcf->user->userID} - {if !$user->isIgnoredUser($__wcf->user->userID)} + {if !$__wcf->getUserProfileHandler()->isIgnoredByUser($user->userID)} {if $__wcf->getUserProfileHandler()->isFollowing($user->userID)}
  • {else} diff --git a/wcfsetup/install/files/lib/data/user/UserProfile.class.php b/wcfsetup/install/files/lib/data/user/UserProfile.class.php index 91e931896a..c4eb5c5c0f 100644 --- a/wcfsetup/install/files/lib/data/user/UserProfile.class.php +++ b/wcfsetup/install/files/lib/data/user/UserProfile.class.php @@ -49,6 +49,12 @@ class UserProfile extends DatabaseObjectDecorator implements ITitledLinkObject { */ protected $ignoredUserIDs; + /** + * list of user ids that are ignoring this user + * @var integer[] + */ + protected $ignoredByUserIDs; + /** * list of follower user ids * @var integer[] @@ -214,6 +220,40 @@ class UserProfile extends DatabaseObjectDecorator implements ITitledLinkObject { return $this->ignoredUserIDs; } + /** + * Returns a list of user ids that are ignoring this user. + * + * @return integer[] + */ + public function getIgnoredByUsers() { + if ($this->ignoredByUserIDs === null) { + $this->ignoredByUserIDs = []; + + if ($this->userID) { + // get ids + $data = UserStorageHandler::getInstance()->getField('ignoredByUserIDs', $this->userID); + + // cache does not exist or is outdated + if ($data === null) { + $sql = "SELECT userID + FROM wcf".WCF_N."_user_ignore + WHERE ignoreUserID = ?"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute([$this->userID]); + $this->ignoredByUserIDs = $statement->fetchAll(\PDO::FETCH_COLUMN); + + // update storage data + UserStorageHandler::getInstance()->update($this->userID, 'ignoredByUserIDs', serialize($this->ignoredByUserIDs)); + } + else { + $this->ignoredByUserIDs = unserialize($data); + } + } + } + + return $this->ignoredByUserIDs; + } + /** * Returns true if current user is following given user id. * @@ -236,7 +276,7 @@ class UserProfile extends DatabaseObjectDecorator implements ITitledLinkObject { /** * Returns true if given user is ignored. - * + * * @param integer $userID * @return boolean */ @@ -244,6 +284,16 @@ class UserProfile extends DatabaseObjectDecorator implements ITitledLinkObject { return in_array($userID, $this->getIgnoredUsers()); } + /** + * Returns true if the given user ignores the current user. + * + * @param integer $userID + * @return boolean + */ + public function isIgnoredByUser($userID) { + return in_array($userID, $this->getIgnoredByUsers()); + } + /** * Returns the user's avatar. * diff --git a/wcfsetup/install/files/lib/data/user/ignore/UserIgnoreAction.class.php b/wcfsetup/install/files/lib/data/user/ignore/UserIgnoreAction.class.php index d38bb073cb..b192be2d8e 100644 --- a/wcfsetup/install/files/lib/data/user/ignore/UserIgnoreAction.class.php +++ b/wcfsetup/install/files/lib/data/user/ignore/UserIgnoreAction.class.php @@ -56,6 +56,7 @@ class UserIgnoreAction extends AbstractDatabaseObjectAction { ]); UserStorageHandler::getInstance()->reset([WCF::getUser()->userID], 'ignoredUserIDs'); + UserStorageHandler::getInstance()->reset([$this->parameters['data']['userID']], 'ignoredByUserIDs'); // check if target user is following the current user $sql = "SELECT * -- 2.20.1