FIX Reduce number of request for list of products

This commit is contained in:
Laurent Destailleur 2019-11-29 11:32:09 +01:00
parent cdf358f276
commit 3acd0bc2ff
2 changed files with 46 additions and 30 deletions

View File

@ -509,36 +509,46 @@ function measuring_units_string($scale = '', $measuring_style = '', $unit = 0, $
function measuringUnitString($unit, $measuring_style = '', $scale = '', $use_short_label = 0)
{
global $langs, $db;
require_once DOL_DOCUMENT_ROOT.'/core/class/cunits.class.php';
$measuringUnits= new CUnits($db);
global $measuring_unit_cache;
if ($scale !== '')
if (empty($measuring_unit_cache[$unit.'_'.$measuring_style.'_'.$scale.'_'.$use_short_label]))
{
$arrayforfilter = array(
't.scale' => $scale,
't.unit_type' => $measuring_style,
't.active' => 1
);
}
else
{
$arrayforfilter = array(
't.rowid' => $unit,
't.unit_type' => $measuring_style,
't.active' => 1
);
}
$result = $measuringUnits->fetchAll('', '', 0, 0, $arrayforfilter);
require_once DOL_DOCUMENT_ROOT.'/core/class/cunits.class.php';
$measuringUnits= new CUnits($db);
if ($result<0) {
return -1;
} else {
if (is_array($measuringUnits->records) && count($measuringUnits->records)>0) {
if ($use_short_label) return $measuringUnits->records[key($measuringUnits->records)]->short_label;
else return $langs->transnoentitiesnoconv($measuringUnits->records[key($measuringUnits->records)]->label);
} else {
return '';
if ($scale !== '')
{
$arrayforfilter = array(
't.scale' => $scale,
't.unit_type' => $measuring_style,
't.active' => 1
);
}
else
{
$arrayforfilter = array(
't.rowid' => $unit,
't.unit_type' => $measuring_style,
't.active' => 1
);
}
$result = $measuringUnits->fetchAll('', '', 0, 0, $arrayforfilter);
if ($result < 0) {
return -1;
} else {
if (is_array($measuringUnits->records) && count($measuringUnits->records)>0) {
if ($use_short_label) $labeltoreturn = $measuringUnits->records[key($measuringUnits->records)]->short_label;
else $labeltoreturn = $langs->transnoentitiesnoconv($measuringUnits->records[key($measuringUnits->records)]->label);
} else {
$labeltoreturn = '';
}
$measuring_unit_cache[$unit.'_'.$measuring_style.'_'.$scale.'_'.$use_short_label] = $labeltoreturn;
return $labeltoreturn;
}
}
else {
return $measuring_unit_cache[$unit.'_'.$measuring_style.'_'.$scale.'_'.$use_short_label];
}
}

View File

@ -783,7 +783,7 @@ if ($resql)
$obj = $db->fetch_object($resql);
// Multilangs
if (! empty($conf->global->MAIN_MULTILANGS)) // si l'option est active
if (! empty($conf->global->MAIN_MULTILANGS)) // If multilang is enabled
{
$sql = "SELECT label";
$sql.= " FROM ".MAIN_DB_PREFIX."product_lang";
@ -801,7 +801,8 @@ if ($resql)
$product_static->id = $obj->rowid;
$product_static->ref = $obj->ref;
$product_static->ref_fourn = $obj->ref_supplier;
$product_static->ref_fourn = $obj->ref_supplier; // deprecated
$product_static->ref_supplier = $obj->ref_supplier;
$product_static->label = $obj->label;
$product_static->type = $obj->fk_product_type;
$product_static->status_buy = $obj->tobuy;
@ -826,15 +827,17 @@ if ($resql)
$product_static->surface = $obj->surface;
$product_static->surface_units = $obj->surface_units;
// STOCK_DISABLE_OPTIM_LOAD can be set to force load_stock whatever is permissions on stock.
if ((! empty($conf->stock->enabled) && $user->rights->stock->lire && $search_type != 1) || ! empty($conf->global->STOCK_DISABLE_OPTIM_LOAD)) // To optimize call of load_stock
{
if ($obj->fk_product_type != 1 || ! empty($conf->global->STOCK_SUPPORTS_SERVICES)) // Not a service
{
$product_static->load_stock('nobatch'); // Load stock_reel + stock_warehouse. This also call load_virtual_stock()
$option = 'nobatch';
if (empty($arrayfields['stock_virtual']['checked'])) $option .= ',novirtual';
$product_static->load_stock($option); // Load stock_reel + stock_warehouse. This can also call load_virtual_stock()
}
}
print '<tr class="oddeven">';
// Ref
@ -845,6 +848,7 @@ if ($resql)
print "</td>\n";
if (! $i) $totalarray['nbfield']++;
}
// Ref supplier
if (! empty($arrayfields['pfp.ref_fourn']['checked']))
{
@ -853,6 +857,7 @@ if ($resql)
print "</td>\n";
if (! $i) $totalarray['nbfield']++;
}
// Label
if (! empty($arrayfields['p.label']['checked']))
{
@ -1120,6 +1125,7 @@ if ($resql)
print '</td>';
if (! $i) $totalarray['nbfield']++;
}
// Action
print '<td class="nowrap center">';
if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined