From 8e4f48678f44e29c653eae23a17b9dfd7b6d38ca Mon Sep 17 00:00:00 2001 From: Taha Yassine Kraiem Date: Fri, 26 Aug 2022 16:26:16 +0100 Subject: [PATCH] feat(alerts): optimized generated query --- api/chalicelib/core/alerts_processor.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/api/chalicelib/core/alerts_processor.py b/api/chalicelib/core/alerts_processor.py index ece75bfe5..c23ef068f 100644 --- a/api/chalicelib/core/alerts_processor.py +++ b/api/chalicelib/core/alerts_processor.py @@ -94,7 +94,7 @@ def can_check(a) -> bool: def Build(a): - params = {"project_id": a["projectId"]} + params = {"project_id": a["projectId"], "now": TimeUTC.now()} full_args = {} j_s = True if a["seriesId"] is not None: @@ -121,8 +121,8 @@ def Build(a): if a["seriesId"] is not None: q += f""" FROM ({subQ}) AS stat""" else: - q += f""" FROM ({subQ} AND timestamp>=%(startDate)s - {"AND sessions.start_ts >= %(startDate)s" if j_s else ""}) AS stat""" + q += f""" FROM ({subQ} AND timestamp>=%(startDate)s AND timestamp<=%(now)s + {"AND sessions.start_ts >= %(startDate)s AND sessions.start_ts <= %(now)s" if j_s else ""}) AS stat""" params = {**params, **full_args, "startDate": TimeUTC.now() - a["options"]["currentPeriod"] * 60 * 1000} else: if a["options"]["change"] == schemas.AlertDetectionChangeType.change: