From 72afae226b47e6ffc487338a96cf4c647cf021fe Mon Sep 17 00:00:00 2001 From: Kraiem Taha Yassine Date: Tue, 16 Jul 2024 14:16:26 +0200 Subject: [PATCH] fix(chalice): fixed missing totalSessions in card-tables in EE (#2390) * fix(chalice): fixed missing totalSessions in card-tables in EE * fix(chalice): fixed missing totalSessions in card-tables in EE --- ee/api/chalicelib/core/sessions_exp.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ee/api/chalicelib/core/sessions_exp.py b/ee/api/chalicelib/core/sessions_exp.py index 2faffa027..804acf5b2 100644 --- a/ee/api/chalicelib/core/sessions_exp.py +++ b/ee/api/chalicelib/core/sessions_exp.py @@ -442,7 +442,8 @@ def search2_table(data: schemas.SessionsSearchPayloadSchema, project_id: int, de if metric_format == schemas.MetricExtendedFormatType.session_count: main_query = f"""SELECT COUNT(DISTINCT {main_col}) OVER () AS main_count, {main_col} AS name, - count(DISTINCT session_id) AS session_count + count(DISTINCT session_id) AS session_count, + COALESCE(SUM(count(DISTINCT session_id)) OVER (), 0) AS total_sessions FROM (SELECT s.session_id AS session_id, {extra_col} {query_part}) AS filtred_sessions @@ -470,11 +471,14 @@ def search2_table(data: schemas.SessionsSearchPayloadSchema, project_id: int, de logging.debug("--------------------") sessions = cur.execute(main_query) count = 0 + total_sessions = 0 if len(sessions) > 0: count = sessions[0]["main_count"] + total_sessions = sessions[0]["total_sessions"] for s in sessions: s.pop("main_count") - sessions = {"count": count, "values": helper.list_to_camel_case(sessions)} + s.pop("total_sessions") + sessions = {"count": count, "totalSessions": total_sessions, "values": helper.list_to_camel_case(sessions)} return sessions