Fix out of memory with a lot of contracts
This commit is contained in:
parent
4c293aa49b
commit
6a7309305b
@ -350,25 +350,43 @@ if ($search_dfyear > 0 && $search_op2df) {
|
|||||||
$sql .= " HAVING MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") <= '".$db->idate(dol_get_last_day($search_dfyear, $search_dfmonth, false))."' AND MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") >= '".$db->idate(dol_get_first_day($search_dfyear, $search_dfmonth, false))."'";
|
$sql .= " HAVING MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") <= '".$db->idate(dol_get_last_day($search_dfyear, $search_dfmonth, false))."' AND MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") >= '".$db->idate(dol_get_first_day($search_dfyear, $search_dfmonth, false))."'";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$sql .= $db->order($sortfield, $sortorder);
|
|
||||||
|
|
||||||
$totalnboflines = 0;
|
$nbtotalofrecords = 0;
|
||||||
$result = $db->query($sql);
|
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
||||||
if ($result) {
|
//$result = $db->query($sql);
|
||||||
$totalnboflines = $db->num_rows($result);
|
//$nbtotalofrecords = $db->num_rows($result);
|
||||||
|
|
||||||
|
if ($search_dfyear > 0 && $search_op2df) {
|
||||||
|
$resql = $db->query($sql, 0, 'auto', 1);
|
||||||
|
while ($db->fetch_object($resql)) {
|
||||||
|
if (empty($nbtotalofrecords)) {
|
||||||
|
$nbtotalofrecords = 1; // We can't make +1 because init value is ''
|
||||||
|
} else {
|
||||||
|
$nbtotalofrecords++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$sqlforcount = preg_replace('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql);
|
||||||
|
$sqlforcount = preg_replace('/LEFT JOIN '.MAIN_DB_PREFIX.'contratdet as cd ON c.rowid = cd.fk_contrat/', '', $sqlforcount);
|
||||||
|
$sqlforcount = preg_replace('/LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=cd.fk_product/', '', $sqlforcount);
|
||||||
|
$sqlforcount = preg_replace('/AND cp.fk_categorie = '.((int) $search_product_category).'/', '', $sqlforcount);
|
||||||
|
$sqlforcount = preg_replace('/GROUP BY.*$/', '', $sqlforcount);
|
||||||
|
|
||||||
|
$resql = $db->query($sqlforcount);
|
||||||
|
$objforcount = $db->fetch_object($resql);
|
||||||
|
$nbtotalofrecords = $objforcount->nbtotalofrecords;
|
||||||
}
|
}
|
||||||
|
|
||||||
$nbtotalofrecords = '';
|
|
||||||
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
|
||||||
$result = $db->query($sql);
|
|
||||||
$nbtotalofrecords = $db->num_rows($result);
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$sql .= $db->order($sortfield, $sortorder);
|
||||||
|
if ($limit) {
|
||||||
$sql .= $db->plimit($limit + 1, $offset);
|
$sql .= $db->plimit($limit + 1, $offset);
|
||||||
|
}
|
||||||
|
|
||||||
$resql = $db->query($sql);
|
$resql = $db->query($sql);
|
||||||
if (!$resql) {
|
if (!$resql) {
|
||||||
@ -508,7 +526,7 @@ print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
|
|||||||
print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
|
print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
|
||||||
print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
|
print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
|
||||||
|
|
||||||
print_barre_liste($langs->trans("ListOfContracts"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $totalnboflines, 'contract', 0, $newcardbutton, '', $limit, 0, 0, 1);
|
print_barre_liste($langs->trans("ListOfContracts"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'contract', 0, $newcardbutton, '', $limit, 0, 0, 1);
|
||||||
|
|
||||||
$topicmail = "SendContractRef";
|
$topicmail = "SendContractRef";
|
||||||
$modelmail = "contract";
|
$modelmail = "contract";
|
||||||
|
|||||||
@ -369,10 +369,14 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
|||||||
/* The slow method does not consume memory on mysql (not tested on pgsql) */
|
/* The slow method does not consume memory on mysql (not tested on pgsql) */
|
||||||
/*$resql = $db->query($sql, 0, 'auto', 1);
|
/*$resql = $db->query($sql, 0, 'auto', 1);
|
||||||
while ($db->fetch_object($resql)) {
|
while ($db->fetch_object($resql)) {
|
||||||
|
if (empty($nbtotalofrecords)) {
|
||||||
|
$nbtotalofrecords = 1; // We can't make +1 because init value is ''
|
||||||
|
} else {
|
||||||
$nbtotalofrecords++;
|
$nbtotalofrecords++;
|
||||||
|
}
|
||||||
}*/
|
}*/
|
||||||
/* The fast and low memory method to get and count full list converts the sql into a sql count */
|
/* The fast and low memory method to get and count full list converts the sql into a sql count */
|
||||||
$sqlforcount = preg_replace('/^SELECT[a-zA-Z0-9\._\s\(\),]+FROM/', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql);
|
$sqlforcount = preg_replace('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql);
|
||||||
$resql = $db->query($sqlforcount);
|
$resql = $db->query($sqlforcount);
|
||||||
$objforcount = $db->fetch_object($resql);
|
$objforcount = $db->fetch_object($resql);
|
||||||
$nbtotalofrecords = $objforcount->nbtotalofrecords;
|
$nbtotalofrecords = $objforcount->nbtotalofrecords;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user