Addoption in get_arbo_each_prod for performance enhancement

This commit is contained in:
Laurent Destailleur 2021-03-14 23:44:20 +01:00
parent ded3beee71
commit 4ca0942229

View File

@ -4223,14 +4223,15 @@ class Product extends CommonObject
* Fonction recursive uniquement utilisee par get_arbo_each_prod, recompose l'arborescence des sousproduits
* Define value of this->res
*
* @param array $prod Products array
* @param string $compl_path Directory path of parents to add before
* @param int $multiply Because each sublevel must be multiplicated by parent nb
* @param int $level Init level
* @param int $id_parent Id parent
* @param array $prod Products array
* @param string $compl_path Directory path of parents to add before
* @param int $multiply Because each sublevel must be multiplicated by parent nb
* @param int $level Init level
* @param int $id_parent Id parent
* @param int $ignore_stock_load Ignore stock load
* @return void
*/
public function fetch_prod_arbo($prod, $compl_path = "", $multiply = 1, $level = 1, $id_parent = 0)
public function fetch_prod_arbo($prod, $compl_path = '', $multiply = 1, $level = 1, $id_parent = 0, $ignore_stock_load = 0)
{
// phpcs:enable
global $conf, $langs;
@ -4243,7 +4244,7 @@ class Product extends CommonObject
$nb = (!empty($desc_pere[1]) ? $desc_pere[1] : '');
$type = (!empty($desc_pere[2]) ? $desc_pere[2] : '');
$label = (!empty($desc_pere[3]) ? $desc_pere[3] : '');
$incdec = !empty($desc_pere[4]) ? $desc_pere[4] : 0;
$incdec = (!empty($desc_pere[4]) ? $desc_pere[4] : 0);
if ($multiply < 1) {
$multiply = 1;
@ -4254,9 +4255,11 @@ class Product extends CommonObject
$tmpproduct = new Product($this->db); // So we initialize tmpproduct only once for all loop.
}
$tmpproduct->fetch($id); // Load product to get ->ref
$tmpproduct->load_stock('nobatch,novirtual'); // Load stock to get true ->stock_reel
//$this->fetch($id); // Load product to get ->ref
//$this->load_stock('nobatch,novirtual'); // Load stock to get true ->stock_reel
if (empty($ignore_stock_load) && ($tmpproduct->isProduct() || !empty($conf->global->STOCK_SUPPORTS_SERVICES))) {
$tmpproduct->load_stock('nobatch,novirtual'); // Load stock to get true ->stock_reel
}
$this->res[] = array(
'id'=>$id, // Id product
'id_parent'=>$id_parent,
@ -4277,7 +4280,7 @@ class Product extends CommonObject
// Recursive call if there is childs to child
if (is_array($desc_pere['childs'])) {
//print 'YYY We go down for '.$desc_pere[3]." -> \n";
$this->fetch_prod_arbo($desc_pere['childs'], $compl_path.$desc_pere[3]." -> ", $desc_pere[1] * $multiply, $level + 1, $id);
$this->fetch_prod_arbo($desc_pere['childs'], $compl_path.$desc_pere[3]." -> ", $desc_pere[1] * $multiply, $level + 1, $id, $ignore_stock_load);
}
}
}
@ -4285,20 +4288,21 @@ class Product extends CommonObject
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Build the tree of subproducts into an array
* this->sousprods is loaded by this->get_sousproduits_arbo()
* Build the tree of subproducts into an array ->res and return it.
* this->sousprods must have been loaded by this->get_sousproduits_arbo()
*
* @param int $multiply Because each sublevel must be multiplicated by parent nb
* @return array $this->res
* @param int $multiply Because each sublevel must be multiplicated by parent nb
* @param int $ignore_stock_load Ignore stock load
* @return array $this->res
*/
public function get_arbo_each_prod($multiply = 1)
public function get_arbo_each_prod($multiply = 1, $ignore_stock_load = 0)
{
// phpcs:enable
$this->res = array();
if (isset($this->sousprods) && is_array($this->sousprods)) {
foreach ($this->sousprods as $prod_name => $desc_product) {
if (is_array($desc_product)) {
$this->fetch_prod_arbo($desc_product, "", $multiply, 1, $this->id);
$this->fetch_prod_arbo($desc_product, "", $multiply, 1, $this->id, $ignore_stock_load);
}
}
}