Skip to content

Commit

Permalink
fix(chalice): fixed heatmaps get location events from CH
Browse files Browse the repository at this point in the history
refactor(chalice): optimized heatmaps get location events from CH
  • Loading branch information
tahayk committed Jul 9, 2024
1 parent 64e121c commit 267c5c6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
8 changes: 4 additions & 4 deletions api/chalicelib/core/heatmaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def search_short_session(data: schemas.HeatMapSessionsSearch, project_id, user_i
elif _depth == 0 and len(session['domURL']) == 0 and len(session['mobsUrl']) == 0:
logger.info("couldn't find an existing replay after 3 iterations for heatmap")

session['events'] = get_page_events(session_id=session["session_id"])
session['events'] = get_page_events(session_id=session["session_id"], project_id=project_id)
else:
logger.debug("No session found for heatmap")

Expand All @@ -236,26 +236,26 @@ def get_selected_session(project_id, session_id):
raise err

session = cur.fetchone()

if session:
session['domURL'] = sessions_mobs.get_urls(session_id=session["session_id"], project_id=project_id)
session['mobsUrl'] = sessions_mobs.get_urls_depercated(session_id=session["session_id"])
if len(session['domURL']) == 0 and len(session['mobsUrl']) == 0:
session["_issue"] = "mob file not found"
logger.info("can't find selected mob file for heatmap")
session['events'] = get_page_events(session_id=session["session_id"])
session['events'] = get_page_events(session_id=session["session_id"], project_id=project_id)

return helper.dict_to_camel_case(session)


def get_page_events(session_id):
def get_page_events(session_id, project_id):
with pg_client.PostgresClient() as cur:
cur.execute(cur.mogrify("""\
SELECT
message_id,
timestamp,
host,
path,
query,
path AS value,
path AS url,
'LOCATION' AS type
Expand Down
31 changes: 17 additions & 14 deletions ee/api/chalicelib/core/heatmaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def search_short_session(data: schemas.HeatMapSessionsSearch, project_id, user_i
elif _depth == 0 and len(session['domURL']) == 0 and len(session['mobsUrl']) == 0:
logger.info("couldn't find an existing replay after 3 iterations for heatmap")

session['events'] = get_page_events(session_id=session["session_id"])
session['events'] = get_page_events(session_id=session["session_id"], project_id=project_id)
else:
logger.debug("No session found for heatmap")

Expand Down Expand Up @@ -258,20 +258,19 @@ def get_selected_session(project_id, session_id):
if len(session['domURL']) == 0 and len(session['mobsUrl']) == 0:
session["_issue"] = "mob file not found"
logger.info("can't find selected mob file for heatmap")
session['events'] = get_page_events(session_id=session["session_id"])
session['events'] = get_page_events(session_id=session["session_id"], project_id=project_id)

return helper.dict_to_camel_case(session)


def get_page_events(session_id):
def get_page_events(session_id, project_id):
with pg_client.PostgresClient() as cur:
cur.execute(cur.mogrify("""\
SELECT
message_id,
timestamp,
host,
path
query,
path AS value,
path AS url,
'LOCATION' AS type
Expand Down Expand Up @@ -384,31 +383,35 @@ def get_selected_session(project_id, session_id):
raise err
if len(session) > 0:
session = session[0]
else:
session = None

if session:
session['domURL'] = sessions_mobs.get_urls(session_id=session["session_id"], project_id=project_id)
session['mobsUrl'] = sessions_mobs.get_urls_depercated(session_id=session["session_id"])
if len(session['domURL']) == 0 and len(session['mobsUrl']) == 0:
session["_issue"] = "mob file not found"
logger.info("can't find selected mob file for heatmap")
session['events'] = get_page_events(session_id=session["session_id"])
session['events'] = get_page_events(session_id=session["session_id"], project_id=project_id)

return helper.dict_to_camel_case(session)


def get_page_events(session_id):
def get_page_events(session_id, project_id):
with ch_client.ClickHouseClient() as cur:
rows = cur.execute("""\
SELECT
message_id,
timestamp,
host,
path,
query,
path AS value,
path AS url,
toUnixTimestamp(datetime)*1000 AS timestamp,
url_host AS host,
url_path AS path,
url_path AS value,
url_path AS url,
'LOCATION' AS type
FROM experimental.events
WHERE session_id = %(session_id)s AS event_type='LOCATION'
ORDER BY timestamp,message_id;""", {"session_id": session_id})
WHERE session_id = %(session_id)s
AND event_type='LOCATION'
AND project_id= %(project_id)s
ORDER BY datetime,message_id;""", {"session_id": session_id,"project_id": project_id})
rows = helper.list_to_camel_case(rows)
return rows

0 comments on commit 267c5c6

Please sign in to comment.