Use the fast count method

This commit is contained in:
Laurent Destailleur 2022-10-04 14:25:21 +02:00
parent dcf1f0bdea
commit 8c46207f32

View File

@ -691,11 +691,20 @@ $sql .= $hookmanager->resPrint;
// Count total nb of records with no order and no limits
$nbtotalofrecords = '';
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
$resql = $db->query($sql);
/*$resql = $db->query($sql);
if ($resql) {
$nbtotalofrecords = $db->num_rows($resql);
} else {
dol_print_error($db);
}*/
/* 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\(\),=<>\:\-\']+\sFROM/', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql);
$resql = $db->query($sqlforcount);
if ($resql) {
$objforcount = $db->fetch_object($resql);
$nbtotalofrecords = $objforcount->nbtotalofrecords;
} else {
dol_print_error($db);
}
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0