From c81f46842bce8bef6fed3ac1d59818376c64be2b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 10 Jan 2022 13:36:28 +0100 Subject: [PATCH] Fix too many load of objects --- htdocs/core/class/commonobject.class.php | 33 ++++++++++++------------ 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 7de04ab0d14..024efa9417e 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -3694,23 +3694,23 @@ abstract class CommonObject /** * Fetch array of objects linked to current object (object of enabled modules only). Links are loaded into * this->linkedObjectsIds array + - * this->linkedObjects array if $loadalsoobjects = 1 + * this->linkedObjects array if $loadalsoobjects = 1 or $loadalsoobjects = type * Possible usage for parameters: * - all parameters empty -> we look all link to current object (current object can be source or target) - * - source id+type -> will get target list linked to source - * - target id+type -> will get source list linked to target - * - source id+type + target type -> will get target list of the type - * - target id+type + target source -> will get source list of the type + * - source id+type -> will get list of targets linked to source + * - target id+type -> will get list of sources linked to target + * - source id+type + target type -> will get list of targets of the type linked to source + * - target id+type + source type -> will get list of sources of the type linked to target * - * @param int $sourceid Object source id (if not defined, id of object) - * @param string $sourcetype Object source type (if not defined, element name of object) - * @param int $targetid Object target id (if not defined, id of object) - * @param string $targettype Object target type (if not defined, elemennt name of object) - * @param string $clause 'OR' or 'AND' clause used when both source id and target id are provided - * @param int $alsosametype 0=Return only links to object that differs from source type. 1=Include also link to objects of same type. - * @param string $orderby SQL 'ORDER BY' clause - * @param int $loadalsoobjects Load also array this->linkedObjects (Use 0 to increase performances) - * @return int <0 if KO, >0 if OK + * @param int $sourceid Object source id (if not defined, id of object) + * @param string $sourcetype Object source type (if not defined, element name of object) + * @param int $targetid Object target id (if not defined, id of object) + * @param string $targettype Object target type (if not defined, element name of object) + * @param string $clause 'OR' or 'AND' clause used when both source id and target id are provided + * @param int $alsosametype 0=Return only links to object that differs from source type. 1=Include also link to objects of same type. + * @param string $orderby SQL 'ORDER BY' clause + * @param int|string $loadalsoobjects Load also array this->linkedObjects. Use 0 to increase performances, Use 1 to load all, Use value of type ('facture', 'facturerec', ...) to load only a type of object. + * @return int <0 if KO, >0 if OK * @see add_object_linked(), updateObjectLinked(), deleteObjectLinked() */ public function fetchObjectLinked($sourceid = null, $sourcetype = '', $targetid = null, $targettype = '', $clause = 'OR', $alsosametype = 1, $orderby = 'sourcetype', $loadalsoobjects = 1) @@ -3892,10 +3892,9 @@ abstract class CommonObject $module = 'mrp'; } - - // Here $module, $classfile and $classname are set + // Here $module, $classfile and $classname are set, we can use them. if ($conf->$module->enabled && (($element != $this->element) || $alsosametype)) { - if ($loadalsoobjects) { + if ($loadalsoobjects && (is_numeric($loadalsoobjects) || ($loadalsoobjects === $objecttype))) { dol_include_once('/'.$classpath.'/'.$classfile.'.class.php'); //print '/'.$classpath.'/'.$classfile.'.class.php '.class_exists($classname); if (class_exists($classname)) {