feat(api): optimised get session details
This commit is contained in:
parent
46e7f5b83e
commit
03e0dbf0e4
4 changed files with 26 additions and 12 deletions
|
|
@ -472,14 +472,13 @@ def search(text, event_type, project_id, source, key):
|
|||
return {"data": rows}
|
||||
|
||||
|
||||
def get_errors_by_session_id(session_id):
|
||||
def get_errors_by_session_id(session_id, project_id):
|
||||
with pg_client.PostgresClient() as cur:
|
||||
cur.execute(cur.mogrify(f"""\
|
||||
SELECT er.*,ur.*, er.timestamp - s.start_ts AS time
|
||||
FROM {event_type.ERROR.table} AS er INNER JOIN public.errors AS ur USING (error_id) INNER JOIN public.sessions AS s USING (session_id)
|
||||
WHERE
|
||||
er.session_id = %(session_id)s
|
||||
ORDER BY timestamp;""", {"session_id": session_id}))
|
||||
WHERE er.session_id = %(session_id)s AND s.project_id=%(project_id)s
|
||||
ORDER BY timestamp;""", {"session_id": session_id, "project_id": project_id}))
|
||||
errors = cur.fetchall()
|
||||
for e in errors:
|
||||
e["stacktrace_parsed_at"] = TimeUTC.datetime_to_timestamp(e["stacktrace_parsed_at"])
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
from chalicelib.utils import helper, pg_client
|
||||
from decouple import config
|
||||
|
||||
|
||||
def get_by_session_id(session_id, project_id):
|
||||
def get_by_session_id(session_id, project_id, start_ts, duration):
|
||||
with pg_client.PostgresClient() as cur:
|
||||
delta = config("events_ts_delta", cast=int, default=5 * 60) * 1000
|
||||
ch_query = """\
|
||||
SELECT
|
||||
timestamp AS datetime,
|
||||
|
|
@ -16,8 +18,13 @@ def get_by_session_id(session_id, project_id):
|
|||
success,
|
||||
COALESCE(status, CASE WHEN success THEN 200 END) AS status
|
||||
FROM events.resources INNER JOIN sessions USING (session_id)
|
||||
WHERE session_id = %(session_id)s AND project_id= %(project_id)s;"""
|
||||
params = {"session_id": session_id, "project_id": project_id}
|
||||
WHERE session_id = %(session_id)s
|
||||
AND project_id= %(project_id)s
|
||||
AND sessions.start_ts=%(start_ts)s
|
||||
AND resources.timestamp>=%(res_start_ts)s
|
||||
AND resources.timestamp>=%(res_end_ts)s;"""
|
||||
params = {"session_id": session_id, "project_id": project_id, "start_ts": start_ts, "duration": duration,
|
||||
"res_start_ts": start_ts - delta, "res_end_ts": start_ts + duration + delta, }
|
||||
cur.execute(cur.mogrify(ch_query, params))
|
||||
rows = cur.fetchall()
|
||||
return helper.list_to_camel_case(rows)
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ def get_by_id2_pg(project_id, session_id, user_id, full_data=False, include_fav_
|
|||
else:
|
||||
data['events'] = events.get_by_sessionId2_pg(project_id=project_id, session_id=session_id,
|
||||
group_clickrage=True)
|
||||
all_errors = events.get_errors_by_session_id(session_id=session_id)
|
||||
all_errors = events.get_errors_by_session_id(session_id=session_id, project_id=project_id)
|
||||
data['stackEvents'] = [e for e in all_errors if e['source'] != "js_exception"]
|
||||
# to keep only the first stack
|
||||
data['errors'] = [errors.format_first_stack_frame(e) for e in all_errors if
|
||||
|
|
@ -94,7 +94,9 @@ def get_by_id2_pg(project_id, session_id, user_id, full_data=False, include_fav_
|
|||
data['userEvents'] = events.get_customs_by_sessionId2_pg(project_id=project_id,
|
||||
session_id=session_id)
|
||||
data['mobsUrl'] = sessions_mobs.get_web(sessionId=session_id)
|
||||
data['resources'] = resources.get_by_session_id(session_id=session_id, project_id=project_id)
|
||||
data['resources'] = resources.get_by_session_id(session_id=session_id, project_id=project_id,
|
||||
start_ts=data["start_ts"],
|
||||
duration=data["duration"])
|
||||
|
||||
data['metadata'] = __group_metadata(project_metadata=data.pop("projectMetadata"), session=data)
|
||||
data['issues'] = issues.get_by_session_id(session_id=session_id)
|
||||
|
|
|
|||
|
|
@ -1,16 +1,22 @@
|
|||
from chalicelib.utils import helper
|
||||
from chalicelib.utils import ch_client
|
||||
from chalicelib.utils.TimeUTC import TimeUTC
|
||||
from decouple import config
|
||||
|
||||
|
||||
def get_by_session_id(session_id, project_id):
|
||||
def get_by_session_id(session_id, project_id, start_ts, duration):
|
||||
with ch_client.ClickHouseClient() as ch:
|
||||
delta = config("events_ts_delta", cast=int, default=5 * 60) * 1000
|
||||
ch_query = """\
|
||||
SELECT
|
||||
datetime,url,type,duration,ttfb,header_size,encoded_body_size,decoded_body_size,success,coalesce(status,if(success, 200, status)) AS status
|
||||
FROM resources
|
||||
WHERE session_id = toUInt64(%(session_id)s) AND project_id=%(project_id)s;"""
|
||||
params = {"session_id": session_id, "project_id": project_id}
|
||||
WHERE session_id = toUInt64(%(session_id)s)
|
||||
AND project_id=%(project_id)s
|
||||
AND datetime >= toDateTime(%(res_start_ts)s / 1000)
|
||||
AND datetime <= toDateTime(%(res_end_ts)s / 1000);"""
|
||||
params = {"session_id": session_id, "project_id": project_id, "start_ts": start_ts, "duration": duration,
|
||||
"res_start_ts": start_ts - delta, "res_end_ts": start_ts + duration + delta, }
|
||||
rows = ch.execute(query=ch_query, params=params)
|
||||
results = []
|
||||
for r in rows:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue