Improved the performance of the check for ignoring users
authorAlexander Ebert <ebert@woltlab.com>
Wed, 9 May 2018 13:06:49 +0000 (15:06 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 9 May 2018 13:06:49 +0000 (15:06 +0200)
Fixes #2566

com.woltlab.wcf/templates/userInformationButtons.tpl
wcfsetup/install/files/lib/data/user/UserProfile.class.php
wcfsetup/install/files/lib/data/user/ignore/UserIgnoreAction.class.php

index 6836711d1247affa8a246881de1e3009a292b393..ca3941c10a7dd909f869765cef46b8b5187808ae 100644 (file)
@@ -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)}
                                                        <li class="jsOnly"><a href="#" data-following="1" data-object-id="{@$user->userID}" class="jsFollowButton jsTooltip" title="{lang}wcf.user.button.unfollow{/lang}"><span class="icon icon16 fa-minus"></span> <span class="invisible">{lang}wcf.user.button.unfollow{/lang}</span></a></li>
                                                {else}
index 91e931896aa38dcad94b6c431fc6a96a433a3247..c4eb5c5c0ff714847d23bd79c1b4d3849b060617 100644 (file)
@@ -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.
         * 
index d38bb073cbe4dc6a76a39951e736124782f795bf..b192be2d8e5db26e0b9ab5c466ce86db82a37562 100644 (file)
@@ -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  *