From 597c1bbc44291dea25931b427508925a3ec6cc73 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Thu, 25 Jun 2015 22:34:01 +0200 Subject: [PATCH] Improve performance of ObjectTypeCache::init() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This method was one of the slowest that get’s regularly called during a request. According to XDebug profiler a request in an empty, stock setup of Burning Board spent 7% of it's time in this method when requesting ?board-list/. 14% if you are including methods called by this method. While that obviously does not represent a real world community optimizing this method is sound, as it’s easily done: After moving the θ(n) calculation that groups object types by their definition into the cache where it belongs the numbers go down to 0.31% (excl) and 1.80% (incl). --- .../files/lib/data/object/type/ObjectTypeCache.class.php | 9 +-------- .../cache/builder/ObjectTypeCacheBuilder.class.php | 9 +++++++-- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/wcfsetup/install/files/lib/data/object/type/ObjectTypeCache.class.php b/wcfsetup/install/files/lib/data/object/type/ObjectTypeCache.class.php index 928c9e5c55..1dbeb1aa56 100644 --- a/wcfsetup/install/files/lib/data/object/type/ObjectTypeCache.class.php +++ b/wcfsetup/install/files/lib/data/object/type/ObjectTypeCache.class.php @@ -57,14 +57,7 @@ class ObjectTypeCache extends SingletonFactory { // get object type cache $this->objectTypes = ObjectTypeCacheBuilder::getInstance()->getData(array(), 'objectTypes'); - foreach ($this->objectTypes as $objectType) { - $definition = $this->getDefinition($objectType->definitionID); - if (!isset($this->groupedObjectTypes[$definition->definitionName])) { - $this->groupedObjectTypes[$definition->definitionName] = array(); - } - - $this->groupedObjectTypes[$definition->definitionName][$objectType->objectType] = $objectType; - } + $this->groupedObjectTypes = ObjectTypeCacheBuilder::getInstance()->getData(array(), 'groupedObjectTypes'); } /** diff --git a/wcfsetup/install/files/lib/system/cache/builder/ObjectTypeCacheBuilder.class.php b/wcfsetup/install/files/lib/system/cache/builder/ObjectTypeCacheBuilder.class.php index e6ef706360..45e97a3b72 100644 --- a/wcfsetup/install/files/lib/system/cache/builder/ObjectTypeCacheBuilder.class.php +++ b/wcfsetup/install/files/lib/system/cache/builder/ObjectTypeCacheBuilder.class.php @@ -22,7 +22,8 @@ class ObjectTypeCacheBuilder extends AbstractCacheBuilder { $data = array( 'categories' => array(), 'definitions' => array(), - 'objectTypes' => array() + 'objectTypes' => array(), + 'groupedObjectTypes' => array() ); // get definitions @@ -48,7 +49,11 @@ class ObjectTypeCacheBuilder extends AbstractCacheBuilder { $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(); while ($row = $statement->fetchArray()) { - $data['objectTypes'][$row['objectTypeID']] = new ObjectType(null, $row); + $data['objectTypes'][$row['objectTypeID']] = $objectType = new ObjectType(null, $row); + + $definition = $data['definitions'][$objectType->definitionID]; + if (!isset($data['groupedObjectTypes'][$definition->definitionName])) $data['groupedObjectTypes'][$definition->definitionName] = array(); + $data['groupedObjectTypes'][$definition->definitionName][$objectType->objectType] = $objectType; } return $data; -- 2.20.1