From 91e6087d1b9cea899bfb5c7f31f5e31e99f96eb3 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 29 Nov 2012 00:07:05 +0100 Subject: [PATCH] Perf: Try to reduce amount of memory used to show events --- htdocs/comm/action/class/actioncomm.class.php | 41 +++++++++++-------- htdocs/core/class/html.formactions.class.php | 28 +++++++++---- 2 files changed, 44 insertions(+), 25 deletions(-) diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index d42ebf136e1..fd1a1e657a6 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -477,12 +477,14 @@ class ActionComm extends CommonObject * @param int $fk_element Id of element action is linked to * @param string $elementtype Type of element action is linked to * @param string $filter Other filter - * @return int <0 if KO, >0 if OK + * @return array <0 if KO, array with actions */ - function getActions($socid=0, $fk_element=0, $elementtype='', $filter='') + static function getActions($db, $socid=0, $fk_element=0, $elementtype='', $filter='') { global $conf, $langs; + $resarray=array(); + $sql = "SELECT a.id"; $sql.= " FROM ".MAIN_DB_PREFIX."actioncomm as a"; $sql.= " WHERE a.entity = ".$conf->entity; @@ -495,27 +497,27 @@ class ActionComm extends CommonObject if (! empty($filter)) $sql.= $filter; dol_syslog(get_class($this)."::getActions sql=".$sql); - $resql=$this->db->query($sql); + $resql=$db->query($sql); if ($resql) { - $num = $this->db->num_rows($resql); + $num = $db->num_rows($resql); if ($num) { for($i=0;$i<$num;$i++) { - $obj = $this->db->fetch_object($resql); - $actioncommstatic = new ActionComm($this->db); + $obj = $db->fetch_object($resql); + $actioncommstatic = new ActionComm($db); $actioncommstatic->fetch($obj->id); - $this->actions[$i] = $actioncommstatic; + $resarray[$i] = $actioncommstatic; } } - $this->db->free($resql); - return 1; + $db->free($resql); + return $resarray; } else { - $this->error=$this->db->lasterror(); + $this->error=$db->lasterror(); return -1; } } @@ -707,21 +709,26 @@ class ActionComm extends CommonObject if ($option=='birthday') $lien = ''; else $lien = ''; $lienfin=''; - //print $this->libelle; + $label=$this->label; + if (empty($label)) $label=$this->libelle; // Fro backward compatibility + //print 'rrr'.$this->libelle; + if ($withpicto == 2) { - $libelle=$langs->trans("Action".$this->type_code); + $libelle=$label; + if (! empty($conf->global->AGENDA_USE_EVENT_TYPE)) $libelle=$langs->trans("Action".$this->type_code); $libelleshort=''; } else if (empty($this->libelle)) { - $libelle=$langs->trans("Action".$this->type_code); - $libelleshort=$langs->trans("Action".$this->type_code,'','','','',$maxlength); + $libelle=$label; + if (! empty($conf->global->AGENDA_USE_EVENT_TYPE)) $libelle=$langs->trans("Action".$this->type_code); + $libelleshort=dol_trunc($label, $maxlength); } else - { - $libelle=$this->libelle; - $libelleshort=dol_trunc($this->libelle,$maxlength); + { + $libelle=$label; + $libelleshort=dol_trunc($label,$maxlength); } if ($withpicto) diff --git a/htdocs/core/class/html.formactions.class.php b/htdocs/core/class/html.formactions.class.php index 94f127f1b5a..07780c1c068 100644 --- a/htdocs/core/class/html.formactions.class.php +++ b/htdocs/core/class/html.formactions.class.php @@ -144,10 +144,10 @@ class FormActions require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php'; - $actioncomm = new ActionComm($this->db); - $actioncomm->getActions($socid, $object->id, $typeelement); + $listofactions=ActionComm::getActions($this->db, $socid, $object->id, $typeelement); + if (is_numeric($listofactions) && $listofactions < 0) dol_print_error($this->db,'FailedToGetActions'); - $num = count($actioncomm->actions); + $num = count($listofactions); if ($num) { if ($typeelement == 'invoice') $title=$langs->trans('ActionsOnBill'); @@ -164,17 +164,29 @@ class FormActions $total = 0; $var=true; print ''; - print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; print "\n"; - foreach($actioncomm->actions as $action) + $userstatic = new User($this->db); + + foreach($listofactions as $action) { + $savlabel=$action->label; + $action->label=$action->ref; + $ref=$action->getNomUrl(1); + $action->label=$savlabel; + $label=$action->getNomUrl(0,38); + $var=!$var; print ''; - print ''; + print ''; + print ''; print ''; - print ''; - $userstatic = new User($this->db); $userstatic->id = $action->author->id; $userstatic->firstname = $action->author->firstname; $userstatic->lastname = $action->author->lastname;
'.$langs->trans('Ref').''.$langs->trans('Date').''.$langs->trans('Action').''.$langs->trans('By').'
'.$langs->trans('Ref').''.$langs->trans('Action').''.$langs->trans('Date').''.$langs->trans('By').'
'.$action->getNomUrl(1).''.$ref.''.$label.''.dol_print_date($action->datep,'day').''.dol_trunc($action->label,32).'