Skip to content

Commit

Permalink
fix(chalice): fixed card-tableOf pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
tahayk committed Jul 2, 2024
1 parent e32fb37 commit d53d44d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 7 additions & 1 deletion api/chalicelib/core/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,10 @@ def search2_table(data: schemas.SessionsSearchPayloadSchema, project_id: int, de
full_args["step_size"] = step_size
with pg_client.PostgresClient() as cur:
if isinstance(metric_of, schemas.MetricOfTable):
full_args["limit"] = data.limit
full_args["limit_s"] = (data.page - 1) * data.limit
full_args["limit_e"] = data.page * data.limit

main_col = "user_id"
extra_col = ""
extra_where = ""
Expand Down Expand Up @@ -356,7 +360,9 @@ def search2_table(data: schemas.SessionsSearchPayloadSchema, project_id: int, de
if metric_format == schemas.MetricExtendedFormatType.session_count:
main_query = f"""SELECT COUNT(*) AS count,
COALESCE(SUM(users_sessions.session_count),0) AS total_sessions,
COALESCE(JSONB_AGG(users_sessions) FILTER ( WHERE rn <= 200 ), '[]'::JSONB) AS values
COALESCE(JSONB_AGG(users_sessions)
FILTER ( WHERE rn > %(limit_s)s
AND rn <= %(limit_e)s ), '[]'::JSONB) AS values
FROM (SELECT {main_col} AS name,
count(DISTINCT session_id) AS session_count,
ROW_NUMBER() OVER (ORDER BY count(full_sessions) DESC) AS rn
Expand Down
6 changes: 4 additions & 2 deletions ee/api/chalicelib/core/sessions_exp.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,9 +408,11 @@ def search2_table(data: schemas.SessionsSearchPayloadSchema, project_id: int, de
full_args["step_size"] = step_size
sessions = []
with ch_client.ClickHouseClient() as cur:
full_args["limit_s"] = 0
full_args["limit_e"] = 200
if isinstance(metric_of, schemas.MetricOfTable):
full_args["limit"] = data.limit
full_args["limit_s"] = (data.page - 1) * data.limit
full_args["limit_e"] = data.page * data.limit

main_col = "user_id"
extra_col = "s.user_id"
extra_where = ""
Expand Down

0 comments on commit d53d44d

Please sign in to comment.