[icinga-checkins] icinga.org: icingaweb2-module-director/fiddle/mfrosch: ImportRowModifier: reduce instantiated objects

git at icinga.org git at icinga.org
Fri Jul 22 13:55:46 CEST 2016


Module: icingaweb2-module-director
Branch: fiddle/mfrosch
Commit: 225e9beec6d0f72d88b6e0456ff2ab176a7b8947
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=225e9beec6d0f72d88b6e0456ff2ab176a7b8947

Author: Thomas Gelf <thomas at gelf.net>
Date:   Wed Jul 20 12:59:02 2016 +0200

ImportRowModifier: reduce instantiated objects

---

 application/tables/ImportsourceHookTable.php   |    7 ++-----
 library/Director/Import/Import.php             |    6 ++----
 library/Director/Objects/ImportRowModifier.php |   14 ++++++++++++++
 3 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/application/tables/ImportsourceHookTable.php b/application/tables/ImportsourceHookTable.php
index 557e7db..1cc4529 100644
--- a/application/tables/ImportsourceHookTable.php
+++ b/application/tables/ImportsourceHookTable.php
@@ -88,11 +88,8 @@ class ImportsourceHookTable extends QuickTable
             if (! array_key_exists($mod->property_name, $propertyModifiers)) {
                 $propertyModifiers[$mod->property_name] = array();
             }
-            $obj = new $mod->provider_class;
-            $obj->setSettings($mod->getSettings());
-            $obj->setDb($this->source->getConnection());
-            $propertyModifiers[$mod->property_name][] = $obj;
-            
+
+            $propertyModifiers[$mod->property_name][] = $mod->getInstance();
         }
 
         foreach ($this->dataCache as & $row) {
diff --git a/library/Director/Import/Import.php b/library/Director/Import/Import.php
index b4de844..4d607a2 100644
--- a/library/Director/Import/Import.php
+++ b/library/Director/Import/Import.php
@@ -234,10 +234,8 @@ class Import
             if (! array_key_exists($mod->property_name, $propertyModifiers)) {
                 $propertyModifiers[$mod->property_name] = array();
             }
-            $obj = new $mod->provider_class;
-            $obj->setSettings($mod->getSettings());
-            $obj->setDb($this->connection);
-            $propertyModifiers[$mod->property_name][] = $obj;
+
+            $propertyModifiers[$mod->property_name][] = $mod->getInstance();
         }
 
         return $propertyModifiers;
diff --git a/library/Director/Objects/ImportRowModifier.php b/library/Director/Objects/ImportRowModifier.php
index f1fd4ad..240074e 100644
--- a/library/Director/Objects/ImportRowModifier.php
+++ b/library/Director/Objects/ImportRowModifier.php
@@ -23,4 +23,18 @@ class ImportRowModifier extends DbObjectWithSettings
     protected $settingsTable = 'import_row_modifier_setting';
 
     protected $settingsRemoteId = 'row_modifier_id';
+
+    private $hookInstance;
+
+    public function getInstance()
+    {
+        if ($this->hookInstance === null) {
+            $obj = new $this->provider_class;
+            $obj->setSettings($this->getSettings());
+            $obj->setDb($this->connection);
+            $this->hookInstance = $obj;
+        }
+
+        return $this->hookInstance;
+    }
 }



More information about the icinga-checkins mailing list