From c034c1bb3359fa3a2ed8032b8046e98503edde8e Mon Sep 17 00:00:00 2001 From: Francis Appels Date: Thu, 17 Nov 2022 10:51:49 +0100 Subject: [PATCH 1/6] Make new method for fast scanlist optional (for the moment). --- htdocs/product/list.php | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/htdocs/product/list.php b/htdocs/product/list.php index e637e478df4..ae7be5009e1 100644 --- a/htdocs/product/list.php +++ b/htdocs/product/list.php @@ -594,20 +594,22 @@ $sql .= $hookmanager->resPrint; //if (GETPOST("toolowstock")) $sql.= " HAVING SUM(s.reel) < p.seuil_stock_alerte"; // Not used yet $nbtotalofrecords = ''; -if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { - /* $result = $db->query($sql); - $nbtotalofrecords = $db->num_rows($result); - */ - /* 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/Ui', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql); - $sqlforcount = preg_replace('/'.preg_quote($linktopfp, '/').'/', '', $sqlforcount); - $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount); - $resql = $db->query($sqlforcount); - if ($resql) { - $objforcount = $db->fetch_object($resql); - $nbtotalofrecords = $objforcount->nbtotalofrecords; +if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) { + if (!getDolGlobalInt('MAIN_ENABLE_FAST_SCANLIST')) { + $result = $db->query($sql); + $nbtotalofrecords = $db->num_rows($result); } else { - dol_print_error($db); + /* Experimental: 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/Ui', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql); + $sqlforcount = preg_replace('/'.preg_quote($linktopfp, '/').'/', '', $sqlforcount); + $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount); + $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 From da1bba6907b3eceb7dd50534c357b7930448fe7c Mon Sep 17 00:00:00 2001 From: Francis Appels Date: Thu, 17 Nov 2022 11:08:46 +0100 Subject: [PATCH 2/6] Use MAIN_FEATURES_LEVEL develop --- htdocs/product/list.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/product/list.php b/htdocs/product/list.php index ae7be5009e1..a77de6b5f27 100644 --- a/htdocs/product/list.php +++ b/htdocs/product/list.php @@ -595,11 +595,11 @@ $sql .= $hookmanager->resPrint; $nbtotalofrecords = ''; if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) { - if (!getDolGlobalInt('MAIN_ENABLE_FAST_SCANLIST')) { + if (getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) { $result = $db->query($sql); $nbtotalofrecords = $db->num_rows($result); } else { - /* Experimental: The fast and low memory method to get and count full list converts the sql into a sql count */ + /* Develop: 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/Ui', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql); $sqlforcount = preg_replace('/'.preg_quote($linktopfp, '/').'/', '', $sqlforcount); $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount); From c3b28bec853c9e550b17bfe0678b26ceb12c1b6f Mon Sep 17 00:00:00 2001 From: Francis Appels Date: Fri, 18 Nov 2022 16:01:43 +0100 Subject: [PATCH 3/6] Revert "Use MAIN_FEATURES_LEVEL develop" This reverts commit da1bba6907b3eceb7dd50534c357b7930448fe7c. --- htdocs/product/list.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/product/list.php b/htdocs/product/list.php index a77de6b5f27..ae7be5009e1 100644 --- a/htdocs/product/list.php +++ b/htdocs/product/list.php @@ -595,11 +595,11 @@ $sql .= $hookmanager->resPrint; $nbtotalofrecords = ''; if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) { - if (getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) { + if (!getDolGlobalInt('MAIN_ENABLE_FAST_SCANLIST')) { $result = $db->query($sql); $nbtotalofrecords = $db->num_rows($result); } else { - /* Develop: The fast and low memory method to get and count full list converts the sql into a sql count */ + /* Experimental: 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/Ui', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql); $sqlforcount = preg_replace('/'.preg_quote($linktopfp, '/').'/', '', $sqlforcount); $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount); From d7cd88e9c3ef54a8cce87a70169f029a211fcf9b Mon Sep 17 00:00:00 2001 From: Francis Appels Date: Fri, 18 Nov 2022 16:02:11 +0100 Subject: [PATCH 4/6] Revert "Make new method for fast scanlist optional (for the moment)." This reverts commit c034c1bb3359fa3a2ed8032b8046e98503edde8e. --- htdocs/product/list.php | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/htdocs/product/list.php b/htdocs/product/list.php index ae7be5009e1..e637e478df4 100644 --- a/htdocs/product/list.php +++ b/htdocs/product/list.php @@ -594,22 +594,20 @@ $sql .= $hookmanager->resPrint; //if (GETPOST("toolowstock")) $sql.= " HAVING SUM(s.reel) < p.seuil_stock_alerte"; // Not used yet $nbtotalofrecords = ''; -if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) { - if (!getDolGlobalInt('MAIN_ENABLE_FAST_SCANLIST')) { - $result = $db->query($sql); - $nbtotalofrecords = $db->num_rows($result); +if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { + /* $result = $db->query($sql); + $nbtotalofrecords = $db->num_rows($result); + */ + /* 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/Ui', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql); + $sqlforcount = preg_replace('/'.preg_quote($linktopfp, '/').'/', '', $sqlforcount); + $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount); + $resql = $db->query($sqlforcount); + if ($resql) { + $objforcount = $db->fetch_object($resql); + $nbtotalofrecords = $objforcount->nbtotalofrecords; } else { - /* Experimental: 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/Ui', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql); - $sqlforcount = preg_replace('/'.preg_quote($linktopfp, '/').'/', '', $sqlforcount); - $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount); - $resql = $db->query($sqlforcount); - if ($resql) { - $objforcount = $db->fetch_object($resql); - $nbtotalofrecords = $objforcount->nbtotalofrecords; - } else { - dol_print_error($db); - } + dol_print_error($db); } if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0 From 43674f385c5f6b1e91a03534f2c55934cae9cdb9 Mon Sep 17 00:00:00 2001 From: Francis Appels Date: Fri, 18 Nov 2022 16:14:14 +0100 Subject: [PATCH 5/6] replace preg_replace by str_replace --- htdocs/product/list.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/htdocs/product/list.php b/htdocs/product/list.php index b96a0f6447e..67d7829d32f 100644 --- a/htdocs/product/list.php +++ b/htdocs/product/list.php @@ -434,6 +434,9 @@ if (!empty($extrafields->attributes[$object->table_element]['label'])) { $parameters = array(); $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook $sql .= $hookmanager->resPrint; + +$sqlfields = $sql; // $sql fields to remove for count total + $sql .= ' FROM '.MAIN_DB_PREFIX.'product as p'; if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) { $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity); @@ -606,7 +609,7 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { $nbtotalofrecords = $db->num_rows($result); */ /* 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/Ui', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql); + $sqlforcount = str_replace($sqlfields, 'SELECT COUNT(*) as nbtotalofrecords', $sql); $sqlforcount = preg_replace('/'.preg_quote($linktopfp, '/').'/', '', $sqlforcount); $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount); $resql = $db->query($sqlforcount); From 9bdd17af1ded4a57a9279f058f06771154efc4bf Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 23 Nov 2022 13:00:50 +0100 Subject: [PATCH 6/6] Update list.php --- htdocs/product/list.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/htdocs/product/list.php b/htdocs/product/list.php index 67d7829d32f..613d0a1c5d6 100644 --- a/htdocs/product/list.php +++ b/htdocs/product/list.php @@ -605,11 +605,8 @@ $sql .= $hookmanager->resPrint; $nbtotalofrecords = ''; if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { - /* $result = $db->query($sql); - $nbtotalofrecords = $db->num_rows($result); - */ /* The fast and low memory method to get and count full list converts the sql into a sql count */ - $sqlforcount = str_replace($sqlfields, 'SELECT COUNT(*) as nbtotalofrecords', $sql); + $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql); $sqlforcount = preg_replace('/'.preg_quote($linktopfp, '/').'/', '', $sqlforcount); $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount); $resql = $db->query($sqlforcount);