feat(chalice): check sessions existance

This commit is contained in:
Taha Yassine Kraiem 2022-09-21 13:57:30 +01:00
parent 67d17a3354
commit d325c03bcb
3 changed files with 25 additions and 0 deletions

View file

@ -1237,3 +1237,15 @@ def count_all():
with pg_client.PostgresClient(unlimited_query=True) as cur:
row = cur.execute(query="SELECT COUNT(session_id) AS count FROM public.sessions")
return row.get("count", 0)
def session_exists(project_id, session_id):
with pg_client.PostgresClient() as cur:
query = cur.mogrify("""SELECT 1
FROM public.sessions
WHERE session_id=%(session_id)s
AND project_id=%(project_id)s""",
{"project_id": project_id, "session_id": session_id})
cur.execute(query)
row = cur.fetchone(query)
return row is not None

View file

@ -913,6 +913,8 @@ def get_live_session(projectId: int, sessionId: str, background_tasks: Backgroun
@app.get('/{projectId}/assist/sessions/{sessionId}/replay', tags=["assist"])
def get_live_session_replay_file(projectId: int, sessionId: str,
context: schemas.CurrentContext = Depends(OR_context)):
if isinstance(sessionId, str) or not sessions.session_exists(project_id=projectId, session_id=sessionId):
return {"errors": ["Replay file not found"]}
path = assist.get_raw_mob_by_id(project_id=projectId, session_id=sessionId)
if path is None:
return {"errors": ["Replay file not found"]}

View file

@ -1542,3 +1542,14 @@ def count_all():
with pg_client.PostgresClient(unlimited_query=True) as cur:
row = cur.execute(query="SELECT COUNT(session_id) AS count FROM public.sessions")
return row.get("count", 0)
def session_exists(project_id, session_id):
with ch_client.ClickHouseClient() as cur:
query = cur.format("""SELECT 1
FROM public.sessions
WHERE session_id=%(session_id)s
AND project_id=%(project_id)s""",
{"project_id": project_id, "session_id": session_id})
row = cur.execute(query)
return row is not None