Fix too many load of objects

This commit is contained in:
Laurent Destailleur 2022-01-10 13:36:28 +01:00
parent 6c9ed0ab6b
commit c81f46842b

View File

@ -3694,22 +3694,22 @@ abstract class CommonObject
/** /**
* Fetch array of objects linked to current object (object of enabled modules only). Links are loaded into * Fetch array of objects linked to current object (object of enabled modules only). Links are loaded into
* this->linkedObjectsIds array + * this->linkedObjectsIds array +
* this->linkedObjects array if $loadalsoobjects = 1 * this->linkedObjects array if $loadalsoobjects = 1 or $loadalsoobjects = type
* Possible usage for parameters: * Possible usage for parameters:
* - all parameters empty -> we look all link to current object (current object can be source or target) * - 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 * - source id+type -> will get list of targets linked to source
* - target id+type -> will get source list linked to target * - target id+type -> will get list of sources linked to target
* - source id+type + target type -> will get target list of the type * - source id+type + target type -> will get list of targets of the type linked to source
* - target id+type + target source -> will get source list of the type * - 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 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 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 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 $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 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 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 string $orderby SQL 'ORDER BY' clause
* @param int $loadalsoobjects Load also array this->linkedObjects (Use 0 to increase performances) * @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 * @return int <0 if KO, >0 if OK
* @see add_object_linked(), updateObjectLinked(), deleteObjectLinked() * @see add_object_linked(), updateObjectLinked(), deleteObjectLinked()
*/ */
@ -3892,10 +3892,9 @@ abstract class CommonObject
$module = 'mrp'; $module = 'mrp';
} }
// Here $module, $classfile and $classname are set, we can use them.
// Here $module, $classfile and $classname are set
if ($conf->$module->enabled && (($element != $this->element) || $alsosametype)) { if ($conf->$module->enabled && (($element != $this->element) || $alsosametype)) {
if ($loadalsoobjects) { if ($loadalsoobjects && (is_numeric($loadalsoobjects) || ($loadalsoobjects === $objecttype))) {
dol_include_once('/'.$classpath.'/'.$classfile.'.class.php'); dol_include_once('/'.$classpath.'/'.$classfile.'.class.php');
//print '/'.$classpath.'/'.$classfile.'.class.php '.class_exists($classname); //print '/'.$classpath.'/'.$classfile.'.class.php '.class_exists($classname);
if (class_exists($classname)) { if (class_exists($classname)) {