Synchronize user profiles with the runtime cache
authorAlexander Ebert <ebert@woltlab.com>
Wed, 31 May 2017 13:02:49 +0000 (15:02 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 31 May 2017 13:02:49 +0000 (15:02 +0200)
See #2283

wcfsetup/install/files/lib/data/user/UserProfile.class.php
wcfsetup/install/files/lib/system/cache/runtime/UserProfileRuntimeCache.class.php

index f89088afb787a3762bd661edfd9be9b6f77eca72..b5adf1d2a346dc3ce4e1cb10e57553a81451fa6d 100644 (file)
@@ -36,12 +36,6 @@ class UserProfile extends DatabaseObjectDecorator implements ITitledLinkObject {
         */
        protected static $baseClass = User::class;
        
-       /**
-        * cached list of user profiles
-        * @var UserProfile[]
-        */
-       protected static $userProfiles = [];
-       
        /**
         * list of ignored user ids
         * @var integer[]
@@ -410,7 +404,7 @@ class UserProfile extends DatabaseObjectDecorator implements ITitledLinkObject {
                        
                        foreach ($userList as $user) {
                                $users[mb_strtolower($user->username)] = $user;
-                               self::$userProfiles[$user->userID] = $user;
+                               UserProfileRuntimeCache::getInstance()->addUserProfile($user);
                        }
                        
                        foreach ($usernames as $username) {
index aebf45b702b4e1fc7916a749efcd244a8b84da45..2da4d46739337d64c182ea1e2ee18461cfe4b25a 100644 (file)
@@ -6,7 +6,7 @@ use wcf\data\user\UserProfileList;
 /**
  * Runtime cache implementation for user profiles.
  *
- * @author     Matthias Schmidt
+ * @author     Alexander Ebert, Matthias Schmidt
  * @copyright  2001-2017 WoltLab GmbH
  * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  * @package    WoltLabSuite\Core\System\Cache\Runtime
@@ -21,4 +21,20 @@ class UserProfileRuntimeCache extends AbstractRuntimeCache {
         * @inheritDoc
         */
        protected $listClassName = UserProfileList::class;
+       
+       /**
+        * Adds a user profile to the cache. This is an internal method that should
+        * not be used on a regular basis.
+        * 
+        * @param       UserProfile     $profile
+        * @since       3.1
+        */
+       public function addUserProfile(UserProfile $profile) {
+               $objectID = $profile->getObjectID();
+               
+               if (!isset($this->objects[$objectID])) {
+                       $this->objectIDs[] = $objectID;
+                       $this->objects[$objectID] = $profile;
+               }
+       }
 }