From 69852a1c2addfbf5344a15eb40ecbd3caef64025 Mon Sep 17 00:00:00 2001 From: daniel Date: Mon, 9 Jul 2018 09:23:19 +0200 Subject: [PATCH] mejora el rendimiento en consulta sql --- pandora_console/include/functions_modules.php | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php index 2f358744e5..59e88d9cdf 100755 --- a/pandora_console/include/functions_modules.php +++ b/pandora_console/include/functions_modules.php @@ -1685,17 +1685,22 @@ function modules_get_previous_data ($id_agent_module, $utimestamp = 0, $string = $table = 'tagente_datos'; } - $sql = sprintf ('SELECT * - FROM ' . $table . ' - WHERE id_agente_modulo = %d - AND utimestamp <= %d - ORDER BY utimestamp DESC', - $id_agent_module, $utimestamp, - $utimestamp - SECONDS_2DAY + $sql = sprintf ( + "SELECT * FROM %s + WHERE id_agente_modulo = %d + AND utimestamp = ( SELECT max(utimestamp) + FROM tagente_datos + WHERE id_agente_modulo = %d + AND utimestamp <= %d )", + $table, + $id_agent_module, + $id_agent_module, + $utimestamp ); $search_in_history_db = db_search_in_history_db($utimestamp); - return db_get_row_sql ($sql, $search_in_history_db); + + return db_get_row_sql($sql, $search_in_history_db); } /**