Add method to improve signatures with embedded objects
authorJoshua Rüsweg <ruesweg@woltlab.com>
Sun, 21 Apr 2019 12:04:45 +0000 (14:04 +0200)
committerJoshua Rüsweg <ruesweg@woltlab.com>
Sun, 21 Apr 2019 12:04:45 +0000 (14:04 +0200)
See #2670

wcfsetup/install/files/lib/system/user/signature/SignatureCache.class.php

index ba549d0ba6257384f7e8e5658018888cafa65cf5..ce9e8080e481203f2c1c3cf5b7cacaf411e3bf80 100644 (file)
@@ -25,6 +25,12 @@ class SignatureCache extends SingletonFactory {
         */
        protected $signatures = [];
        
+       /**
+        * The userIDs which are cached by the message embedded object manager. 
+        * @var integer[]
+        */
+       protected $cachedUserIDs = [];
+       
        /**
         * Returns a parsed user signature.
         * 
@@ -37,7 +43,9 @@ class SignatureCache extends SingletonFactory {
                                $this->htmlOutputProcessor = new HtmlOutputProcessor();
                        }
                        
-                       MessageEmbeddedObjectManager::getInstance()->loadObjects('com.woltlab.wcf.user.signature', [$user->userID]);
+                       if (!in_array($user->userID, $this->cachedUserIDs)) {
+                               $this->cacheUserSignature([$user->userID]);
+                       }
                        
                        $this->htmlOutputProcessor->setContext('com.woltlab.wcf.user.signature', $user->userID);
                        $this->htmlOutputProcessor->process($user->signature, 'com.woltlab.wcf.user.signature', $user->userID);
@@ -46,4 +54,16 @@ class SignatureCache extends SingletonFactory {
                
                return $this->signatures[$user->userID];
        }
+       
+       /**
+        * Loads the embedded objects for the given users. 
+        * 
+        * @param       integer[]       $userIDs
+        * @since       5.2
+        */
+       public function cacheUserSignature(array $userIDs) {
+               $this->cachedUserIDs = array_merge($this->cachedUserIDs, $userIDs);
+               
+               MessageEmbeddedObjectManager::getInstance()->loadObjects('com.woltlab.wcf.user.signature', $userIDs);
+       }
 }