feat(api): fixed sessions search with bookmark
This commit is contained in:
parent
783008bd0f
commit
b736ee40d2
1 changed files with 14 additions and 10 deletions
|
|
@ -251,8 +251,15 @@ def search2_pg(data: schemas.SessionsSearchPayloadSchema, project_id, user_id, e
|
||||||
# print("--------------------")
|
# print("--------------------")
|
||||||
# print(main_query)
|
# print(main_query)
|
||||||
# print("--------------------")
|
# print("--------------------")
|
||||||
|
try:
|
||||||
cur.execute(main_query)
|
cur.execute(main_query)
|
||||||
|
except Exception as err:
|
||||||
|
print("--------- SESSIONS SEARCH QUERY EXCEPTION -----------")
|
||||||
|
print(main_query)
|
||||||
|
print("--------- PAYLOAD -----------")
|
||||||
|
print(data.dict())
|
||||||
|
print("--------------------")
|
||||||
|
raise err
|
||||||
if errors_only:
|
if errors_only:
|
||||||
return helper.list_to_camel_case(cur.fetchall())
|
return helper.list_to_camel_case(cur.fetchall())
|
||||||
|
|
||||||
|
|
@ -387,10 +394,6 @@ def search_query_parts(data, error_status, errors_only, favorite_only, issue, pr
|
||||||
"s.duration IS NOT NULL"
|
"s.duration IS NOT NULL"
|
||||||
]
|
]
|
||||||
extra_from = ""
|
extra_from = ""
|
||||||
fav_only_join = ""
|
|
||||||
if favorite_only and not errors_only:
|
|
||||||
fav_only_join = "LEFT JOIN public.user_favorite_sessions AS fs ON fs.session_id = s.session_id"
|
|
||||||
# extra_constraints.append("fs.user_id = %(userId)s")
|
|
||||||
events_query_part = ""
|
events_query_part = ""
|
||||||
if len(data.filters) > 0:
|
if len(data.filters) > 0:
|
||||||
meta_keys = None
|
meta_keys = None
|
||||||
|
|
@ -628,6 +631,9 @@ def search_query_parts(data, error_status, errors_only, favorite_only, issue, pr
|
||||||
event_where = ["ms.project_id = %(projectId)s", "main.timestamp >= %(startDate)s",
|
event_where = ["ms.project_id = %(projectId)s", "main.timestamp >= %(startDate)s",
|
||||||
"main.timestamp <= %(endDate)s", "ms.start_ts >= %(startDate)s",
|
"main.timestamp <= %(endDate)s", "ms.start_ts >= %(startDate)s",
|
||||||
"ms.start_ts <= %(endDate)s", "ms.duration IS NOT NULL"]
|
"ms.start_ts <= %(endDate)s", "ms.duration IS NOT NULL"]
|
||||||
|
if favorite_only and not errors_only:
|
||||||
|
event_from += "INNER JOIN public.user_favorite_sessions AS fs USING(session_id)"
|
||||||
|
event_where.append("fs.user_id = %(userId)s")
|
||||||
else:
|
else:
|
||||||
event_from = "%s"
|
event_from = "%s"
|
||||||
event_where = ["main.timestamp >= %(startDate)s", "main.timestamp <= %(endDate)s",
|
event_where = ["main.timestamp >= %(startDate)s", "main.timestamp <= %(endDate)s",
|
||||||
|
|
@ -946,16 +952,14 @@ def search_query_parts(data, error_status, errors_only, favorite_only, issue, pr
|
||||||
MIN(timestamp) AS first_event_ts,
|
MIN(timestamp) AS first_event_ts,
|
||||||
MAX(timestamp) AS last_event_ts
|
MAX(timestamp) AS last_event_ts
|
||||||
FROM ({events_joiner.join(events_query_from)}) AS u
|
FROM ({events_joiner.join(events_query_from)}) AS u
|
||||||
GROUP BY 1
|
GROUP BY 1"""
|
||||||
{fav_only_join}"""
|
|
||||||
else:
|
else:
|
||||||
events_query_part = f"""SELECT
|
events_query_part = f"""SELECT
|
||||||
event_0.session_id,
|
event_0.session_id,
|
||||||
MIN(event_0.timestamp) AS first_event_ts,
|
MIN(event_0.timestamp) AS first_event_ts,
|
||||||
MAX(event_{event_index - 1}.timestamp) AS last_event_ts
|
MAX(event_{event_index - 1}.timestamp) AS last_event_ts
|
||||||
FROM {events_joiner.join(events_query_from)}
|
FROM {events_joiner.join(events_query_from)}
|
||||||
GROUP BY 1
|
GROUP BY 1"""
|
||||||
{fav_only_join}"""
|
|
||||||
else:
|
else:
|
||||||
data.events = []
|
data.events = []
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue