Merge branch 'ent-11566-giss-optimizar-la-query-de-la-seccion-detalle-de-alertas' into 'develop'

Fix alert list queries performance

See merge request artica/pandorafms!6099
This commit is contained in:
Gorka Sanchez 2023-06-14 14:39:49 +00:00
commit 66db70c905
2 changed files with 46 additions and 21 deletions

View File

@ -230,10 +230,23 @@ if ($get_agent_alerts_agent_view) {
' AND id_agent_module IN (
SELECT tam.id_agente_modulo
FROM tagente_modulo tam
WHERE tam.id_agente IN (SELECT ta.id_agente
FROM tagente ta LEFT JOIN tagent_secondary_group tasg ON
ta.id_agente = tasg.id_agent
WHERE (ta.id_grupo IN (%s) OR tasg.id_group IN (%s)))) ',
WHERE tam.id_agente IN (
SELECT
ta.id_agente
FROM
tagente ta
WHERE
ta.id_grupo IN (%s)
)
OR tam.id_agente IN (
SELECT
DISTINCT(tasg.id_agent)
FROM
tagent_secondary_group tasg
WHERE
tasg.id_group IN (%s)
)
) ',
implode(',', $id_groups),
implode(',', $id_groups)
);
@ -835,10 +848,18 @@ if ($get_agent_alerts_datatable === true) {
' AND id_agent_module IN (
SELECT tam.id_agente_modulo
FROM tagente_modulo tam
WHERE tam.id_agente IN (SELECT ta.id_agente
FROM tagente ta LEFT JOIN tagent_secondary_group tasg ON
ta.id_agente = tasg.id_agent
WHERE (ta.id_grupo IN (%s) OR tasg.id_group IN (%s)))) ',
WHERE
tam.id_agente IN (
SELECT ta.id_agente
FROM tagente ta
WHERE ta.id_grupo IN (%s)
)
OR tam.id_agente IN (
SELECT DISTINCT(tasg.id_agent)
FROM tagent_secondary_group tasg
WHERE tasg.id_group IN (%s)
)
) ',
implode(',', $id_groups),
implode(',', $id_groups)
);

View File

@ -2191,15 +2191,19 @@ function get_group_alerts(
} else {
$subQuery = 'SELECT id_agente_modulo
FROM tagente_modulo tam
WHERE delete_pending = 0 AND tam.disabled = 0
AND id_agente IN (SELECT id_agente
WHERE delete_pending = 0
AND tam.disabled = 0
AND id_agente IN (
SELECT ta.id_agente
FROM tagente ta
LEFT JOIN tagent_secondary_group tasg
ON ta.id_agente = tasg.id_agent
WHERE ta.disabled = 0
AND
id_grupo IN ('.implode(',', $id_group).')
OR id_group IN ('.implode(',', $id_group).'))';
AND ta.id_grupo IN ('.implode(',', $id_group).')
)
OR tam.id_agente IN (
SELECT DISTINCT(tasg.id_agent)
FROM tagent_secondary_group tasg
WHERE tasg.id_group IN ('.implode(',', $id_group).')
)';
}
} else {
$subQuery = 'SELECT id_agente_modulo