mejora el rendimiento en consulta sql

This commit is contained in:
daniel 2018-07-09 09:23:19 +02:00
parent 49ed21b93d
commit 69852a1c2a
1 changed files with 13 additions and 8 deletions

View File

@ -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);
}
/**