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,6 +509,10 @@ function measuring_units_string($scale = '', $measuring_style = '', $unit = 0, $
function measuringUnitString($unit, $measuring_style = '', $scale = '', $use_short_label = 0) function measuringUnitString($unit, $measuring_style = '', $scale = '', $use_short_label = 0)
{ {
global $langs, $db; global $langs, $db;
global $measuring_unit_cache;
if (empty($measuring_unit_cache[$unit.'_'.$measuring_style.'_'.$scale.'_'.$use_short_label]))
{
require_once DOL_DOCUMENT_ROOT.'/core/class/cunits.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/cunits.class.php';
$measuringUnits= new CUnits($db); $measuringUnits= new CUnits($db);
@ -534,11 +538,17 @@ function measuringUnitString($unit, $measuring_style = '', $scale = '', $use_sho
return -1; return -1;
} else { } else {
if (is_array($measuringUnits->records) && count($measuringUnits->records)>0) { if (is_array($measuringUnits->records) && count($measuringUnits->records)>0) {
if ($use_short_label) return $measuringUnits->records[key($measuringUnits->records)]->short_label; if ($use_short_label) $labeltoreturn = $measuringUnits->records[key($measuringUnits->records)]->short_label;
else return $langs->transnoentitiesnoconv($measuringUnits->records[key($measuringUnits->records)]->label); else $labeltoreturn = $langs->transnoentitiesnoconv($measuringUnits->records[key($measuringUnits->records)]->label);
} else { } else {
return ''; $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); $obj = $db->fetch_object($resql);
// Multilangs // 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 = "SELECT label";
$sql.= " FROM ".MAIN_DB_PREFIX."product_lang"; $sql.= " FROM ".MAIN_DB_PREFIX."product_lang";
@ -801,7 +801,8 @@ if ($resql)
$product_static->id = $obj->rowid; $product_static->id = $obj->rowid;
$product_static->ref = $obj->ref; $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->label = $obj->label;
$product_static->type = $obj->fk_product_type; $product_static->type = $obj->fk_product_type;
$product_static->status_buy = $obj->tobuy; $product_static->status_buy = $obj->tobuy;
@ -826,15 +827,17 @@ if ($resql)
$product_static->surface = $obj->surface; $product_static->surface = $obj->surface;
$product_static->surface_units = $obj->surface_units; $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 ((! 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 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">'; print '<tr class="oddeven">';
// Ref // Ref
@ -845,6 +848,7 @@ if ($resql)
print "</td>\n"; print "</td>\n";
if (! $i) $totalarray['nbfield']++; if (! $i) $totalarray['nbfield']++;
} }
// Ref supplier // Ref supplier
if (! empty($arrayfields['pfp.ref_fourn']['checked'])) if (! empty($arrayfields['pfp.ref_fourn']['checked']))
{ {
@ -853,6 +857,7 @@ if ($resql)
print "</td>\n"; print "</td>\n";
if (! $i) $totalarray['nbfield']++; if (! $i) $totalarray['nbfield']++;
} }
// Label // Label
if (! empty($arrayfields['p.label']['checked'])) if (! empty($arrayfields['p.label']['checked']))
{ {
@ -1120,6 +1125,7 @@ if ($resql)
print '</td>'; print '</td>';
if (! $i) $totalarray['nbfield']++; if (! $i) $totalarray['nbfield']++;
} }
// Action // Action
print '<td class="nowrap center">'; 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 if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined