Optimize memory and perf for list of stock movements
This commit is contained in:
parent
23083427e8
commit
baec6aa169
@ -566,25 +566,44 @@ include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
|
|||||||
$parameters = array();
|
$parameters = array();
|
||||||
$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
|
$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
|
||||||
$sql .= $hookmanager->resPrint;
|
$sql .= $hookmanager->resPrint;
|
||||||
$sql .= $db->order($sortfield, $sortorder);
|
|
||||||
|
|
||||||
|
// Count total nb of records
|
||||||
$nbtotalofrecords = '';
|
$nbtotalofrecords = '';
|
||||||
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
||||||
$result = $db->query($sql);
|
/* This old and fast method to get and count full list returns all record so use a high amount of memory.
|
||||||
$nbtotalofrecords = $db->num_rows($result);
|
$resql = $db->query($sql);
|
||||||
|
$nbtotalofrecords = $db->num_rows($resql);
|
||||||
|
*/
|
||||||
|
/* The slow method does not consume memory on mysql (not tested on pgsql) */
|
||||||
|
/*$resql = $db->query($sql, 0, 'auto', 1);
|
||||||
|
while ($db->fetch_object($resql)) {
|
||||||
|
$nbtotalofrecords++;
|
||||||
|
}*/
|
||||||
|
/* This fast and low memory method to get and count full list converts the sql into a sql count */
|
||||||
|
$sqlforcount = preg_replace('/^SELECT[a-z0-9\._\s\(\),]+FROM/i', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql);
|
||||||
|
$resql = $db->query($sqlforcount);
|
||||||
|
$objforcount = $db->fetch_object($resql);
|
||||||
|
$nbtotalofrecords = $objforcount->nbtotalofrecords;
|
||||||
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
|
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
|
||||||
$page = 0;
|
$page = 0;
|
||||||
$offset = 0;
|
$offset = 0;
|
||||||
}
|
}
|
||||||
|
$db->free($resql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$sql .= $db->order($sortfield, $sortorder);
|
||||||
|
if ($limit) {
|
||||||
$sql .= $db->plimit($limit + 1, $offset);
|
$sql .= $db->plimit($limit + 1, $offset);
|
||||||
|
}
|
||||||
|
|
||||||
//print $sql;
|
//print $sql;
|
||||||
|
|
||||||
$resql = $db->query($sql);
|
$resql = $db->query($sql);
|
||||||
|
if (!$resql) {
|
||||||
|
dol_print_error($db);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
if ($resql) {
|
|
||||||
$product = new Product($db);
|
$product = new Product($db);
|
||||||
$object = new Entrepot($db);
|
$object = new Entrepot($db);
|
||||||
|
|
||||||
@ -1285,6 +1304,7 @@ if ($resql) {
|
|||||||
print "</tr>\n";
|
print "</tr>\n";
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
$db->free($resql);
|
$db->free($resql);
|
||||||
|
|
||||||
print "</table>";
|
print "</table>";
|
||||||
@ -1320,10 +1340,6 @@ if ($resql) {
|
|||||||
print "<br>\n";
|
print "<br>\n";
|
||||||
//print '</td></tr>';
|
//print '</td></tr>';
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
dol_print_error($db);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// End of page
|
// End of page
|
||||||
llxFooter();
|
llxFooter();
|
||||||
|
|||||||
@ -789,7 +789,12 @@ while ($i < ($limit ? min($num, $limit) : $num)) {
|
|||||||
$objp = $db->fetch_object($resql);
|
$objp = $db->fetch_object($resql);
|
||||||
|
|
||||||
if (!empty($conf->global->STOCK_SUPPORTS_SERVICES) || $objp->fk_product_type == 0) {
|
if (!empty($conf->global->STOCK_SUPPORTS_SERVICES) || $objp->fk_product_type == 0) {
|
||||||
$prod->fetch($objp->rowid);
|
$result = $prod->fetch($objp->rowid);
|
||||||
|
if ($result < 0) {
|
||||||
|
dol_print_error($db);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
$prod->load_stock('warehouseopen, warehouseinternal'.(!$usevirtualstock?', novirtual':''), $draftchecked);
|
$prod->load_stock('warehouseopen, warehouseinternal'.(!$usevirtualstock?', novirtual':''), $draftchecked);
|
||||||
|
|
||||||
// Multilangs
|
// Multilangs
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user