Pour un inventaire fusion, j'ajoute plusieurs logiciels au meme pc et
donc fait plusieurs computer_softwareversion->add().

Ce patch permet de mettre en cache les infos du pc pour is_template et
is_deleted

Gain de 8% (ca evite le getFromDB xx fois)

merci d'avance

David Durieux
++
Index: inc/computer_softwareversion.class.php
===================================================================
--- inc/computer_softwareversion.class.php	(revision 19807)
+++ inc/computer_softwareversion.class.php	(working copy)
@@ -49,6 +49,8 @@
 
    static public $log_history_2_add    = Log::HISTORY_INSTALL_SOFTWARE;
    static public $log_history_2_delete = Log::HISTORY_UNINSTALL_SOFTWARE;
+   
+   var $computer_cache = array();
 
    static function getTypeName($nb=0) {
       return _n('Installation', 'Installations', $nb);
@@ -64,11 +66,17 @@
    function prepareInputForAdd($input) {
 
       // Get template and deleted information from computer
-      $computer = new Computer();
-      if ($computer->getFromDB($input['computers_id'])) {
-         $input['is_template'] = $computer->getField('is_template');
-         $input['is_deleted']  = $computer->getField('is_deleted');
+      $computers_id = $input['computers_id'];
+      if (!isset($this->computer_cache[$computers_id])) {
+         $computer = new Computer();
+         if ($computer->getFromDB($computers_id)) {
+            $this->computer_cache[$computers_id] = $computer->fields;
+         }
       }
+      if (isset($this->computer_cache[$computers_id])) {
+         $input['is_template'] = $this->computer_cache[$computers_id]['is_template'];
+         $input['is_deleted']  = $this->computer_cache[$computers_id]['is_deleted'];
+      }
       return parent::prepareInputForAdd($input);
    }

_______________________________________________
Glpi-dev mailing list
[email protected]
https://mail.gna.org/listinfo/glpi-dev

Reply via email to