From: Marcel Werk Date: Sun, 21 Sep 2014 18:58:01 +0000 (+0200) Subject: Avoid multiple loading of same embedded objects X-Git-Tag: 2.1.0_Alpha_1~303^2~3 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=9b14e60a989db3a572ed5ac6940a2a7920b5e5d8;p=GitHub%2FWoltLab%2FWCF.git Avoid multiple loading of same embedded objects Closes #1795 --- diff --git a/wcfsetup/install/files/lib/system/message/embedded/object/MessageEmbeddedObjectManager.class.php b/wcfsetup/install/files/lib/system/message/embedded/object/MessageEmbeddedObjectManager.class.php index c4361a2d34..393b6b5cf4 100644 --- a/wcfsetup/install/files/lib/system/message/embedded/object/MessageEmbeddedObjectManager.class.php +++ b/wcfsetup/install/files/lib/system/message/embedded/object/MessageEmbeddedObjectManager.class.php @@ -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) {