From 765a84e2eb9ec325fc892994d18361796f6dfd7e Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 14 Jul 2023 07:27:04 +0200 Subject: [PATCH 1/2] refs #5819 Added param to call zone_getLeaves --- modules/zone/back/methods/zone/getLeaves.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/zone/back/methods/zone/getLeaves.js b/modules/zone/back/methods/zone/getLeaves.js index a6db3b711..aeed9f3a2 100644 --- a/modules/zone/back/methods/zone/getLeaves.js +++ b/modules/zone/back/methods/zone/getLeaves.js @@ -38,7 +38,7 @@ module.exports = Self => { Object.assign(myOptions, options); const [res] = await Self.rawSql( - `CALL zone_getLeaves(?, ?, ?)`, + `CALL zone_getLeaves(?, ?, ?, FALSE)`, [id, parentId, search], myOptions ); From 3c013110d35a96aadb7f78b226f3de590bf4957a Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 18 Jul 2023 07:32:45 +0200 Subject: [PATCH 2/2] refs #5819 Changed structure sql --- db/dump/structure.sql | 121 ++++++++++++++++++++++++++---------------- 1 file changed, 74 insertions(+), 47 deletions(-) diff --git a/db/dump/structure.sql b/db/dump/structure.sql index ee5fb40a1..4e7127310 100644 --- a/db/dump/structure.sql +++ b/db/dump/structure.sql @@ -77831,7 +77831,7 @@ BEGIN LEAVE cur1Loop; END IF; - CALL zone_getLeaves2(vZoneFk, NULL, NULL); + CALL zone_getLeaves(vZoneFk, NULL, NULL, TRUE); myLoop: LOOP SET vGeoFk = NULL; @@ -77844,7 +77844,7 @@ BEGIN LEAVE myLoop; END IF; - CALL zone_getLeaves2(vZoneFk, vGeoFk, NULL); + CALL zone_getLeaves(vZoneFk, vGeoFk, NULL, TRUE); UPDATE tmp.zoneNodes SET isChecked = TRUE WHERE geoFk = vGeoFk; @@ -78130,55 +78130,58 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `zone_getLeaves`(vSelf INT, vParentFk INT, vSearch VARCHAR(255)) -BEGIN +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zone_getLeaves`( + vSelf INT, + vParentFk INT, + vSearch VARCHAR(255), + vHasInsert BOOL +) +BEGIN /** * Devuelve las ubicaciones incluidas en la ruta y que sean hijos de parentFk. * @param vSelf Id de la zona * @param vParentFk Id del geo a calcular - * @param vSearch cadena a buscar + * @param vSearch Cadena a buscar + * @param vHasInsert Indica si inserta en tmp.zoneNodes + * Optional @table tmp.zoneNodes(geoFk, name, parentFk, sons, isChecked, zoneFk) */ DECLARE vIsNumber BOOL; - DECLARE vIsSearch BOOL DEFAULT vSearch IS NOT NULL AND vSearch != ''; + DECLARE vIsSearch BOOL DEFAULT vSearch IS NOT NULL AND vSearch <> ''; - DROP TEMPORARY TABLE IF EXISTS tNodes; - CREATE TEMPORARY TABLE tNodes + CREATE OR REPLACE TEMPORARY TABLE tNodes (UNIQUE (id)) ENGINE = MEMORY - SELECT id - FROM zoneGeo + SELECT id + FROM zoneGeo LIMIT 0; IF vIsSearch THEN SET vIsNumber = vSearch REGEXP '^[0-9]+$'; - + INSERT INTO tNodes - SELECT id + SELECT id FROM zoneGeo WHERE (vIsNumber AND `name` = vSearch) OR (!vIsNumber AND `name` LIKE CONCAT('%', vSearch, '%')) LIMIT 1000; - + ELSEIF vParentFk IS NULL THEN INSERT INTO tNodes - SELECT geoFk + SELECT geoFk FROM zoneIncluded WHERE zoneFk = vSelf; END IF; IF vParentFk IS NULL THEN - DROP TEMPORARY TABLE IF EXISTS tChilds; - CREATE TEMPORARY TABLE tChilds + CREATE OR REPLACE TEMPORARY TABLE tChilds + (INDEX(id)) ENGINE = MEMORY - SELECT id - FROM tNodes; + SELECT id FROM tNodes; - DROP TEMPORARY TABLE IF EXISTS tParents; - CREATE TEMPORARY TABLE tParents + CREATE OR REPLACE TEMPORARY TABLE tParents + (INDEX(id)) ENGINE = MEMORY - SELECT id - FROM zoneGeo - LIMIT 0; + SELECT id FROM zoneGeo LIMIT 0; myLoop: LOOP DELETE FROM tParents; @@ -78186,43 +78189,67 @@ BEGIN SELECT parentFk id FROM zoneGeo g JOIN tChilds c ON c.id = g.id - WHERE g.parentFk IS NOT NULL; - + WHERE g.parentFk IS NOT NULL; + INSERT IGNORE INTO tNodes - SELECT id - FROM tParents; - - IF ROW_COUNT() = 0 THEN + SELECT id FROM tParents; + + IF NOT ROW_COUNT() THEN LEAVE myLoop; END IF; - + DELETE FROM tChilds; INSERT INTO tChilds - SELECT id - FROM tParents; + SELECT id FROM tParents; END LOOP; - + DROP TEMPORARY TABLE tChilds, tParents; END IF; - IF !vIsSearch THEN + IF NOT vIsSearch THEN INSERT IGNORE INTO tNodes - SELECT id + SELECT id FROM zoneGeo WHERE parentFk <=> vParentFk; END IF; - SELECT g.id, - g.name, - g.parentFk, - g.sons, - isIncluded selected - FROM zoneGeo g - JOIN tNodes n ON n.id = g.id - LEFT JOIN zoneIncluded i ON i.geoFk = g.id AND i.zoneFk = vSelf - ORDER BY `depth`, selected DESC, name; + CREATE OR REPLACE TEMPORARY TABLE tZones + SELECT g.id, + g.name, + g.parentFk, + g.sons, + NOT g.sons OR `type` = 'country' isChecked, + i.isIncluded selected, + g.`depth`, + vSelf + FROM zoneGeo g + JOIN tNodes n ON n.id = g.id + LEFT JOIN zoneIncluded i ON i.geoFk = g.id + AND i.zoneFk = vSelf + ORDER BY g.`depth`, selected DESC, g.name; - DROP TEMPORARY TABLE tNodes; + IF vHasInsert THEN + INSERT IGNORE INTO tmp.zoneNodes(geoFk, name, parentFk, sons, isChecked, zoneFk) + SELECT id, + name, + parentFk, + sons, + isChecked, + vSelf + FROM tZones + WHERE selected + OR (selected IS NULL AND vParentFk IS NOT NULL); + ELSE + SELECT id, + name, + parentFk, + sons, + selected + FROM tZones + ORDER BY `depth`, selected DESC, name; + END IF; + + DROP TEMPORARY TABLE tNodes, tZones; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -78540,7 +78567,7 @@ BEGIN INDEX(geoFk)) ENGINE = MEMORY; - CALL zone_getLeaves2(vSelf, NULL , NULL); + CALL zone_getLeaves(vSelf, NULL , NULL, TRUE); UPDATE tmp.zoneNodes zn SET isChecked = 0 @@ -78553,7 +78580,7 @@ BEGIN WHERE NOT isChecked LIMIT 1; - CALL zone_getLeaves2(vSelf, vGeoFk, NULL); + CALL zone_getLeaves(vSelf, vGeoFk, NULL, TRUE); UPDATE tmp.zoneNodes SET isChecked = TRUE WHERE geoFk = vGeoFk;