[icinga-checkins] icinga.org: icingaweb2-module-director/master: IcingaObject: loadAllByType should respect PrefetchCache

git at icinga.org git at icinga.org
Mon Oct 31 17:21:26 CET 2016


Module: icingaweb2-module-director
Branch: master
Commit: 672a45b26e76a9147db9ffeb776c4da56eaa95e2
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=672a45b26e76a9147db9ffeb776c4da56eaa95e2

Author: Markus Frosch <markus.frosch at icinga.com>
Date:   Mon Oct 31 17:17:56 2016 +0100

IcingaObject: loadAllByType should respect PrefetchCache

---

 library/Director/Objects/IcingaObject.php |   12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/library/Director/Objects/IcingaObject.php b/library/Director/Objects/IcingaObject.php
index 101350f..dda5903 100644
--- a/library/Director/Objects/IcingaObject.php
+++ b/library/Director/Objects/IcingaObject.php
@@ -2101,12 +2101,22 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
 
     public static function loadAllByType($type, Db $db, $query = null, $keyColumn = 'object_name')
     {
+        /** @var DbObject $class */
         $class = self::classByType($type);
 
         if (is_array($class::create()->getKeyName())) {
             return $class::loadAll($db, $query);
         } else {
-            return $class::loadAll($db, $query, $keyColumn);
+            if (PrefetchCache::shouldBeUsed() && $query === null && $keyColumn === 'object_name') {
+                $result = array();
+                foreach ($class::prefetchAll($db) as $row) {
+                    $result[$row->object_name] = $row;
+                }
+                return $result;
+            }
+            else {
+                return $class::loadAll($db, $query, $keyColumn);
+            }
         }
     }
 



More information about the icinga-checkins mailing list