Avoid multiple loading of same embedded objects
authorMarcel Werk <burntime@woltlab.com>
Sun, 21 Sep 2014 18:58:01 +0000 (20:58 +0200)
committerMarcel Werk <burntime@woltlab.com>
Sun, 21 Sep 2014 18:58:01 +0000 (20:58 +0200)
Closes #1795

wcfsetup/install/files/lib/system/message/embedded/object/MessageEmbeddedObjectManager.class.php

index c4361a2d34cc83b14803be01d5c916dbcdbc2e26..393b6b5cf4cd89e794a8872e207b83007a499a78 100644 (file)
@@ -116,6 +116,7 @@ class MessageEmbeddedObjectManager extends SingletonFactory {
                $conditionBuilder->add('messageObjectTypeID = ?', array(ObjectTypeCache::getInstance()->getObjectTypeIDByName('com.woltlab.wcf.message', $messageObjectType)));
                $conditionBuilder->add('messageID IN (?)', array($messageIDs));
                
+               // get object ids
                $sql = "SELECT  *
                        FROM    wcf".WCF_N."_message_embedded_object
                        ".$conditionBuilder;
@@ -123,15 +124,23 @@ class MessageEmbeddedObjectManager extends SingletonFactory {
                $statement->execute($conditionBuilder->getParameters());
                $embeddedObjects = array();
                while ($row = $statement->fetchArray()) {
+                       if (isset($this->embeddedObjects[$row['embeddedObjectTypeID']][$row['embeddedObjectID']])) {
+                               // embedded object already loaded
+                               continue;
+                       }
+                       
+                       // group objects by object type
                        if (!isset($embeddedObjects[$row['embeddedObjectTypeID']])) $embeddedObjects[$row['embeddedObjectTypeID']] = array();
                        $embeddedObjects[$row['embeddedObjectTypeID']][] = $row['embeddedObjectID'];
                        
+                       // store message to embedded object assignment
                        if (!isset($this->messageEmbeddedObjects[$row['messageObjectTypeID']][$row['messageID']][$row['embeddedObjectTypeID']])) {
                                $this->messageEmbeddedObjects[$row['messageObjectTypeID']][$row['messageID']][$row['embeddedObjectTypeID']] = array();
                        }
                        $this->messageEmbeddedObjects[$row['messageObjectTypeID']][$row['messageID']][$row['embeddedObjectTypeID']][] = $row['embeddedObjectID'];
                }
                
+               // load objects
                foreach ($embeddedObjects as $embeddedObjectTypeID => $objectIDs) {
                        if (!isset($this->embeddedObjects[$embeddedObjectTypeID])) $this->embeddedObjects[$embeddedObjectTypeID] = array();
                        foreach ($this->getEmbeddedObjectHandler($embeddedObjectTypeID)->loadObjects(array_unique($objectIDs)) as $objectID => $object) {