fmsystem-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Fmsystem-commits] [10301] property: cache return values


From: Sigurd Nes
Subject: [Fmsystem-commits] [10301] property: cache return values
Date: Tue, 23 Oct 2012 08:56:38 +0000

Revision: 10301
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=10301
Author:   sigurdne
Date:     2012-10-23 08:56:37 +0000 (Tue, 23 Oct 2012)
Log Message:
-----------
property: cache return values

Modified Paths:
--------------
    trunk/property/inc/class.custom_fields.inc.php
    trunk/property/inc/class.soentity.inc.php

Modified: trunk/property/inc/class.custom_fields.inc.php
===================================================================
--- trunk/property/inc/class.custom_fields.inc.php      2012-10-23 07:16:54 UTC 
(rev 10300)
+++ trunk/property/inc/class.custom_fields.inc.php      2012-10-23 08:56:37 UTC 
(rev 10301)
@@ -547,6 +547,13 @@
 
                public function get_translated_value($data, $location_id)
                {
+                       static $cache_lb = array();
+                       static $cache_contact = array();
+                       static $cache_vendor = array();
+                       static $cache_ch = array();
+                       static $cache_account = array();
+                       static $cache_custom_lookup = array();
+
                        if(!$data['value'])
                        {
                                return $data['value'];
@@ -564,41 +571,65 @@
                                case 'LB':
                                        if($data['attrib_id'])
                                        {
-                                               $sql="SELECT value FROM 
$choice_table WHERE $attribute_filter AND attrib_id=" .(int)$data['attrib_id']. 
"  AND id=" . (int)$data['value'];
-                                               $this->_db2->query($sql);
-                                               $this->_db2->next_record();
-                                               $ret =  $this->_db2->f('value');
+                                               
if(!isset($cache_lb[$location_id][$data['attrib_id']][$data['value']]) || $ret 
!=$cache_lb[$location_id][$data['attrib_id']][$data['value']])
+                                               {
+                                                       $sql="SELECT value FROM 
$choice_table WHERE $attribute_filter AND attrib_id=" .(int)$data['attrib_id']. 
"  AND id=" . (int)$data['value'];
+                                                       
$this->_db2->query($sql);
+                                                       
$this->_db2->next_record();
+                                                       $ret =  
$this->_db2->f('value');
+                                                       
$cache_lb[$location_id][$data['attrib_id']][$data['value']] = $ret;
+                                               }
                                        }
                                        break;
                                case 'AB':
-                                       $contact_data   = 
$this->contacts->read_single_entry($data['value'],array('fn'));
-                                       $ret =  $contact_data[0]['fn'];
+                                       
if(!isset($cache_contact[$data['value']]) || $ret!= 
$cache_contact[$data['value']])
+                                       {
+                                               $contact_data   = 
$this->contacts->read_single_entry($data['value'],array('fn'));
+                                               $ret =  $contact_data[0]['fn'];
+                                               $cache_contact[$data['value']] 
= $ret;
+                                       }
                                        break;
                                case 'ABO':
-                                       $contact_data   = 
$this->contacts->get_principal_organizations_data($data['value']);
-                                       $ret = $contact_data[0]['org_name'];
+                                       
if(!isset($cache_contact[$data['value']]) || $ret!= 
$cache_contact[$data['value']])
+                                       {
+                                               $contact_data   = 
$this->contacts->get_principal_organizations_data($data['value']);
+                                               $ret = 
$contact_data[0]['org_name'];
+                                               $cache_contact[$data['value']] 
= $ret;
+                                       }
                                        break;
                                case 'VENDOR':
-                                       $sql="SELECT org_name FROM fm_vendor 
where id=" . (int)$data['value'];
-                                       $this->_db2->query($sql);
-                                       $this->_db2->next_record();
-                                       $ret =  $this->_db2->f('org_name',true);
+                                       
if(!isset($cache_vendor[$data['value']]) || $ret!= 
$cache_vendor[$data['value']])
+                                       {
+                                               $sql="SELECT org_name FROM 
fm_vendor where id=" . (int)$data['value'];
+                                               $this->_db2->query($sql);
+                                               $this->_db2->next_record();
+                                               $ret =  
$this->_db2->f('org_name',true);
+                                               $cache_vendor[$data['value']] = 
$ret;
+                                       }
                                        break;
                                case 'CH':
-                                       $ch = explode(',', trim($data['value'], 
','));
-                                       if (isset($ch) AND is_array($ch))
+                                       if($data['attrib_id'])
                                        {
-                                               for ($k=0;$k<count($ch);$k++)
+                                               $ret = '';
+                                               
if(!isset($cache_ch[$location_id][$data['attrib_id']][$data['value']]) || $ret 
!=$cache_ch[$location_id][$data['attrib_id']][$data['value']])
                                                {
-                                                       $sql="SELECT value FROM 
$choice_table WHERE $attribute_filter AND attrib_id= " . 
(int)$data['attrib_id'] . ' AND id = ' . (int)$ch[$k];
-                                                       
$this->_db2->query($sql);
-                                                       while 
($this->_db2->next_record())
+                                                       $ch = explode(',', 
trim($data['value'], ','));
+                                                       if (isset($ch) AND 
is_array($ch))
                                                        {
-                                                               
$ch_value[]=$this->_db2->f('value');
+                                                               for 
($k=0;$k<count($ch);$k++)
+                                                               {
+                                                                       
$sql="SELECT value FROM $choice_table WHERE $attribute_filter AND attrib_id= " 
. (int)$data['attrib_id'] . ' AND id = ' . (int)$ch[$k];
+                                                                       
$this->_db2->query($sql);
+                                                                       while 
($this->_db2->next_record())
+                                                                       {
+                                                                       
$ch_value[]=$this->_db2->f('value');
+                                                                       }
+                                                               }
+                                                               $ret =  
@implode(",", $ch_value);
+                                                               
unset($ch_value);
                                                        }
+                                                       
$cache_ch[$location_id][$data['attrib_id']][$data['value']] = $ret;
                                                }
-                                               $ret =  @implode(",", 
$ch_value);
-                                               unset($ch_value);
                                        }
                                        break;
                                case 'D':
@@ -615,11 +646,71 @@
                                        $ret =  
phpgw::safe_redirect($data['value']);
                                        break;
                                case 'user':
-                                       $ret =   
$GLOBALS['phpgw']->accounts->get($data['value'])->__toString();
+                                       
if(!isset($cache_vendor[$data['value']]) || $ret!= 
$cache_vendor[$data['value']])
+                                       {
+                                               $ret =   
$GLOBALS['phpgw']->accounts->get($data['value'])->__toString();
+                                               $cache_vendor[$data['value']] = 
$ret;
+                                       }
                                        break;
                                case 'pwd':
                                        $ret =   lang('yes');
                                        break;
+                               case 'custom1':
+                                       
+                                       $ret = '';
+                                       if($data['value'] && 
$data['get_single_function'])
+                                       {
+                                               
if(!$data['get_single_function_input'])
+                                               {
+                                                       
$data['get_single_function_input'] = $data['value'];
+                                               }
+                                               $_compare_key = 
$this->_get_compare_key($data['get_single_function'], 
$data['get_single_function_input']);
+                                               
if(!isset($cache_custom_lookup[$_compare_key]) || $ret != 
$cache_custom_lookup[$_compare_key])
+                                               {
+                                                       $ret = 
execMethod($data['get_single_function'], $data['get_single_function_input']);
+                                                       
$cache_custom_lookup[$_compare_key] = $ret;
+                                               }
+                                       }
+                                       else if($data['value'] && 
$data['get_list_function'])
+                                       {
+                                               $_compare_key = 
$this->_get_compare_key($data['get_list_function'], 
$data['get_list_function_input']);
+                                               
if(!isset($cache_custom_lookup[$_compare_key]) || $_list != 
$cache_custom_lookup[$_compare_key])
+                                               {
+                                                       $_list = 
execMethod($data['get_list_function'], $data['get_list_function_input']);
+                                                       
$cache_custom_lookup[$_compare_key] = $_list;
+                                               }
+
+                                               if(isset($_list) && 
is_array($_list))
+                                               {
+                                                       foreach ($_list as 
$_key => $_entry)
+                                                       {
+                                                               if 
($_entry['id'] == $data['value'])
+                                                               {
+                                                                       $ret = 
$_entry['name'];
+                                                                       break;
+                                                               }
+                                                       }
+                                               }
+                                       }
+
+                                       break;
+                               case 'custom2':
+                               case 'custom3':
+                                       if($data['value'] && 
$data['get_single_function'])
+                                       {
+                                               
if(!$data['get_single_function_input'])
+                                               {
+                                                       
$data['get_single_function_input'] = $data['value'];
+                                               }
+                                               $_compare_key = 
$this->_get_compare_key($data['get_single_function'], 
$data['get_single_function_input']);
+                                               
if(!isset($cache_custom_lookup[$_compare_key]) || $ret != 
$cache_custom_lookup[$_compare_key])
+                                               {
+                                                       $ret = 
execMethod($data['get_single_function'], $data['get_single_function_input']);
+                                                       
$cache_custom_lookup[$_compare_key] = $ret;
+                                               }
+                                       }
+
+                                       break;
                                default:
                                        if(is_array($data['value']))
                                        {

Modified: trunk/property/inc/class.soentity.inc.php
===================================================================
--- trunk/property/inc/class.soentity.inc.php   2012-10-23 07:16:54 UTC (rev 
10300)
+++ trunk/property/inc/class.soentity.inc.php   2012-10-23 08:56:37 UTC (rev 
10301)
@@ -428,11 +428,16 @@
                                $i      = count($uicols['name']);
                                while ($this->db->next_record())
                                {
-                                       $uicols['input_type'][]         = 
'text';
-                                       $uicols['name'][]                       
= $this->db->f('column_name');
-                                       $uicols['descr'][]                      
= $this->db->f('input_text');
-                                       $uicols['statustext'][]         = 
$this->db->f('statustext');
-                                       $uicols['datatype'][$i]         = 
$this->db->f('datatype');
+                                       $uicols['input_type'][]                 
                        = 'text';
+                                       $uicols['name'][]                       
                                = $this->db->f('column_name');
+                                       $uicols['descr'][]                      
                                = $this->db->f('input_text');
+                                       $uicols['statustext'][]                 
                        = $this->db->f('statustext');
+                                       $uicols['datatype'][$i]                 
                        = $this->db->f('datatype');
+                                       $uicols['get_list_function'][$i]        
                = $this->db->f('get_list_function',true);
+                                       $uicols['get_list_function_input'][$i]  
        = $this->db->f('get_list_function_input') ? 
unserialize($this->db->f('get_list_function_input', true)) : '';
+                                       $uicols['get_single_function'][$i]      
                = $this->db->f('get_single_function',true);
+                                       
$uicols['get_single_function_input'][$i]        = 
$this->db->f('get_single_function_input') ? 
unserialize($this->db->f('get_single_function_input', true)) : '';
+
                                        $uicols['sortable'][$i]         = true;
                                        $uicols['exchange'][$i]         = false;
                                        $uicols['formatter'][$i]        = '';
@@ -822,19 +827,24 @@
                                        }
                                        $dataset[$j][$field] = array
                                        (
-                                               'value'         => $value,
-                                               'datatype'      => 
$uicols['datatype'][$key],
-                                               'attrib_id'     => 
$uicols['cols_return_extra'][$key]['attrib_id']
+                                               'value'                         
                => $value,
+                                               'datatype'                      
                => $uicols['datatype'][$key],
+                                               'attrib_id'                     
                => $uicols['cols_return_extra'][$key]['attrib_id'],
+                                               'get_list_function'             
=> $uicols['get_list_function'][$key],
+                                               'get_list_function_input'       
=> $uicols['get_list_function_input'][$key],
+                                               'get_single_function'           
=> $uicols['get_single_function'][$key],
+                                               'get_single_function_input'     
=> $uicols['get_single_function_input'][$key]
                                        );
                                }
 
+
                                $dataset[$j]['num']['value'] = 
$dataset[$j]['id']['value'];
 
                                $dataset[$j]['entity_id'] = array
                                        (
                                                'value'         => $entity_id,
                                                'datatype'      => false,
-                                               'attrib_id'     => false
+                                               'attrib_id'     => false,
                                        );
                                $dataset[$j]['cat_id'] = array
                                        (
@@ -1095,15 +1105,19 @@
                                $i      = count($uicols['name']);
                                while ($this->db->next_record())
                                {
-                                       $uicols['input_type'][]         = 
'text';
-                                       $uicols['name'][]                       
= $this->db->f('column_name');
-                                       $uicols['descr'][]                      
= $this->db->f('input_text');
-                                       $uicols['statustext'][]         = 
$this->db->f('statustext');
-                                       $uicols['datatype'][$i]         = 
$this->db->f('datatype');
-                                       $uicols['sortable'][$i]         = true;
-                                       $uicols['exchange'][$i]         = false;
-                                       $uicols['formatter'][$i]        = '';
-                                       $uicols['classname'][$i]        = '';
+                                       $uicols['input_type'][]                 
                        = 'text';
+                                       $uicols['name'][]                       
                                = $this->db->f('column_name');
+                                       $uicols['descr'][]                      
                                = $this->db->f('input_text');
+                                       $uicols['statustext'][]                 
                        = $this->db->f('statustext');
+                                       $uicols['datatype'][$i]                 
                        = $this->db->f('datatype');
+                                       $uicols['get_list_function'][$i]        
                = $this->db->f('get_list_function',true);
+                                       $uicols['get_list_function_input'][$i]  
        = $this->db->f('get_list_function_input') ? 
unserialize($this->db->f('get_list_function_input', true)) : '';
+                                       $uicols['get_single_function'][$i]      
                = $this->db->f('get_single_function',true);
+                                       
$uicols['get_single_function_input'][$i]        = 
$this->db->f('get_single_function_input') ? 
unserialize($this->db->f('get_single_function_input', true)) : '';
+                                       $uicols['sortable'][$i]                 
                        = true;
+                                       $uicols['exchange'][$i]                 
                        = false;
+                                       $uicols['formatter'][$i]                
                        = '';
+                                       $uicols['classname'][$i]                
                        = '';
 
                                        $uicols['cols_return_extra'][$i] = array
                                                (
@@ -1447,11 +1461,16 @@
                                foreach($cols_return as $key => $field)
                                {
                                        $dataset[$j][$field] = array
-                                               (
-                                                       'value'         => 
$this->db->f($field),
-                                                       'datatype'      => 
$uicols['datatype'][$key],
-                                                       'attrib_id'     => 
$uicols['cols_return_extra'][$key]['attrib_id']
-                                               );
+                                       (
+                                               'value'                         
                => $this->db->f($field),
+                                               'datatype'                      
                => $uicols['datatype'][$key],
+                                               'attrib_id'                     
                => $uicols['cols_return_extra'][$key]['attrib_id'],
+                                               'get_list_function'             
=> $uicols['get_list_function'][$key],
+                                               'get_list_function_input'       
=> $uicols['get_list_function_input'][$key],
+                                               'get_single_function'           
=> $uicols['get_single_function'][$key],
+                                               'get_single_function_input'     
=> $uicols['get_single_function_input'][$key]
+
+                                       );
                                }
                                $dataset[$j]['entity_id'] = array
                                        (




reply via email to

[Prev in Thread] Current Thread [Next in Thread]