From 3ed8b3c27d00d21ae27372097a01124de6fb4504 Mon Sep 17 00:00:00 2001 From: Kraiem Taha Yassine Date: Tue, 18 Feb 2025 16:37:37 +0100 Subject: [PATCH] Dev (#3041) * refactor(chalice): refactored code * refactor(DB): changed delta * refactor(chalice): product analytics log refactoring --- .../core/metrics/product_analytics_ch.py | 17 +++++++++++------ api/chalicelib/utils/metrics_helper.py | 3 --- .../db/init_dbs/postgresql/1.22.0/1.22.0.sql | 8 ++++---- .../db/init_dbs/postgresql/1.22.0/1.22.0.sql | 8 ++++---- 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/api/chalicelib/core/metrics/product_analytics_ch.py b/api/chalicelib/core/metrics/product_analytics_ch.py index 3bc997525..afd3e52d3 100644 --- a/api/chalicelib/core/metrics/product_analytics_ch.py +++ b/api/chalicelib/core/metrics/product_analytics_ch.py @@ -487,10 +487,12 @@ WITH {initial_sessions_cte} SELECT * FROM pre_ranked_events;""" logger.debug("---------Q1-----------") - ch.execute(query=ch_query1, parameters=params) + ch_query1 = ch.format(query=ch_query1, parameters=params) + logger.debug(ch_query1) + ch.execute(query=ch_query1) if time() - _now > 2: logger.warning(f">>>>>>>>>PathAnalysis long query EE ({int(time() - _now)}s)<<<<<<<<<") - logger.warning(ch.format(query=ch_query1, parameters=params)) + logger.warning(ch_query1) logger.warning("----------------------") _now = time() @@ -512,10 +514,11 @@ SELECT * FROM ranked_events {q2_extra_condition if q2_extra_condition else ""};""" logger.debug("---------Q2-----------") - ch.execute(query=ch_query2, parameters=params) + ch_query2 = ch.format(query=ch_query2, parameters=params) + ch.execute(query=ch_query2) if time() - _now > 2: logger.warning(f">>>>>>>>>PathAnalysis long query EE ({int(time() - _now)}s)<<<<<<<<<") - logger.warning(ch.format(query=ch_query2, parameters=params)) + logger.warning(ch_query2) logger.warning("----------------------") _now = time() @@ -625,10 +628,12 @@ FROM ranked_events ) AS chart_steps ORDER BY event_number_in_session, sessions_count DESC;""" logger.debug("---------Q3-----------") - rows = ch.execute(query=ch_query3, parameters=params) + ch_query3 = ch.format(query=ch_query3, parameters=params) + logger.debug(ch_query3) + rows = ch.execute(query=ch_query3) if time() - _now > 2: logger.warning(f">>>>>>>>>PathAnalysis long query EE ({int(time() - _now)}s)<<<<<<<<<") - logger.warning(ch.format(query=ch_query3, parameters=params)) + logger.warning(ch_query3) logger.warning("----------------------") return __transform_journey(rows=rows, reverse_path=reverse) diff --git a/api/chalicelib/utils/metrics_helper.py b/api/chalicelib/utils/metrics_helper.py index a6ee927bc..7bf9c94f8 100644 --- a/api/chalicelib/utils/metrics_helper.py +++ b/api/chalicelib/utils/metrics_helper.py @@ -2,8 +2,6 @@ from typing import List def get_step_size(startTimestamp, endTimestamp, density, decimal=False, factor=1000): - print("-------density:") - print(density) step_size = (endTimestamp // factor - startTimestamp // factor) if density <= 1: return step_size @@ -17,7 +15,6 @@ def complete_missing_steps(rows: List[dict], start_timestamp: int, end_timestamp result = [] i = 0 for t in range(start_timestamp, end_timestamp, step): - print(t) if i >= len(rows) or rows[i][time_key] > t: neutral[time_key] = t result.append(neutral.copy()) diff --git a/ee/scripts/schema/db/init_dbs/postgresql/1.22.0/1.22.0.sql b/ee/scripts/schema/db/init_dbs/postgresql/1.22.0/1.22.0.sql index d7ed6c5ba..fbedb48a0 100644 --- a/ee/scripts/schema/db/init_dbs/postgresql/1.22.0/1.22.0.sql +++ b/ee/scripts/schema/db/init_dbs/postgresql/1.22.0/1.22.0.sql @@ -27,10 +27,10 @@ DROP TABLE IF EXISTS public.user_favorite_errors; DROP TABLE IF EXISTS public.user_viewed_errors; ALTER TABLE IF EXISTS public.sessions_notes - ADD COLUMN start_at integer, - ADD COLUMN end_at integer, - ADD COLUMN thumbnail text, - ADD COLUMN updated_at timestamp DEFAULT NULL, + ADD COLUMN IF NOT EXISTS start_at integer, + ADD COLUMN IF NOT EXISTS end_at integer, + ADD COLUMN IF NOT EXISTS thumbnail text, + ADD COLUMN IF NOT EXISTS updated_at timestamp DEFAULT NULL, ALTER COLUMN message DROP NOT NULL; DELETE diff --git a/scripts/schema/db/init_dbs/postgresql/1.22.0/1.22.0.sql b/scripts/schema/db/init_dbs/postgresql/1.22.0/1.22.0.sql index 340929e68..a08ba5048 100644 --- a/scripts/schema/db/init_dbs/postgresql/1.22.0/1.22.0.sql +++ b/scripts/schema/db/init_dbs/postgresql/1.22.0/1.22.0.sql @@ -27,10 +27,10 @@ DROP TABLE IF EXISTS public.user_favorite_errors; DROP TABLE IF EXISTS public.user_viewed_errors; ALTER TABLE IF EXISTS public.sessions_notes - ADD COLUMN start_at integer, - ADD COLUMN end_at integer, - ADD COLUMN thumbnail text, - ADD COLUMN updated_at timestamp DEFAULT NULL, + ADD COLUMN IF NOT EXISTS start_at integer, + ADD COLUMN IF NOT EXISTS end_at integer, + ADD COLUMN IF NOT EXISTS thumbnail text, + ADD COLUMN IF NOT EXISTS updated_at timestamp DEFAULT NULL, ALTER COLUMN message DROP NOT NULL; DELETE