From 37db48ceecce830df0977e7d19b0c73da2b527cc Mon Sep 17 00:00:00 2001 From: Taha Yassine Kraiem Date: Thu, 24 Feb 2022 17:54:08 +0100 Subject: [PATCH] feat(api): fixed get sessions list if no-metadata is available feat(DB): v1.5.2 changes --- api/chalicelib/core/sessions.py | 8 ++++---- ee/scripts/helm/db/init_dbs/postgresql/1.5.2/1.5.2.sql | 8 ++++++++ ee/scripts/helm/db/init_dbs/postgresql/init_schema.sql | 2 +- scripts/helm/db/init_dbs/postgresql/1.5.2/1.5.2.sql | 8 ++++++++ scripts/helm/db/init_dbs/postgresql/init_schema.sql | 2 +- 5 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 ee/scripts/helm/db/init_dbs/postgresql/1.5.2/1.5.2.sql create mode 100644 scripts/helm/db/init_dbs/postgresql/1.5.2/1.5.2.sql diff --git a/api/chalicelib/core/sessions.py b/api/chalicelib/core/sessions.py index c095ce344..d180cccc7 100644 --- a/api/chalicelib/core/sessions.py +++ b/api/chalicelib/core/sessions.py @@ -197,8 +197,8 @@ def search2_pg(data: schemas.SessionsSearchPayloadSchema, project_id, user_id, f MIN(full_sessions.start_ts) AS first_session_ts, ROW_NUMBER() OVER (ORDER BY count(full_sessions) DESC) AS rn FROM (SELECT *, ROW_NUMBER() OVER (PARTITION BY user_id ORDER BY start_ts DESC) AS rn - FROM (SELECT DISTINCT ON(s.session_id) {SESSION_PROJECTION_COLS}, - {",".join([f'metadata_{m["index"]}' for m in meta_keys])} + FROM (SELECT DISTINCT ON(s.session_id) {SESSION_PROJECTION_COLS} + {"," if len(meta_keys)>0 else ""}{",".join([f'metadata_{m["index"]}' for m in meta_keys])} {query_part} ORDER BY s.session_id desc) AS filtred_sessions ORDER BY favorite DESC, issue_score DESC, {sort} {data.order}) AS full_sessions @@ -209,8 +209,8 @@ def search2_pg(data: schemas.SessionsSearchPayloadSchema, project_id, user_id, f meta_keys = metadata.get(project_id=project_id) main_query = cur.mogrify(f"""SELECT COUNT(full_sessions) AS count, COALESCE(JSONB_AGG(full_sessions) FILTER (WHERE rn <= 200), '[]'::JSONB) AS sessions FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY favorite DESC, issue_score DESC, session_id desc, start_ts desc) AS rn - FROM (SELECT DISTINCT ON(s.session_id) {SESSION_PROJECTION_COLS}, - {",".join([f'metadata_{m["index"]}' for m in meta_keys])} + FROM (SELECT DISTINCT ON(s.session_id) {SESSION_PROJECTION_COLS} + {"," if len(meta_keys)>0 else ""}{",".join([f'metadata_{m["index"]}' for m in meta_keys])} {query_part} ORDER BY s.session_id desc) AS filtred_sessions ORDER BY favorite DESC, issue_score DESC, {sort} {data.order}) AS full_sessions;""", diff --git a/ee/scripts/helm/db/init_dbs/postgresql/1.5.2/1.5.2.sql b/ee/scripts/helm/db/init_dbs/postgresql/1.5.2/1.5.2.sql new file mode 100644 index 000000000..8ec804b02 --- /dev/null +++ b/ee/scripts/helm/db/init_dbs/postgresql/1.5.2/1.5.2.sql @@ -0,0 +1,8 @@ +BEGIN; +CREATE OR REPLACE FUNCTION openreplay_version() + RETURNS text AS +$$ +SELECT 'v1.5.2-ee' +$$ LANGUAGE sql IMMUTABLE; + +COMMIT; \ No newline at end of file diff --git a/ee/scripts/helm/db/init_dbs/postgresql/init_schema.sql b/ee/scripts/helm/db/init_dbs/postgresql/init_schema.sql index a6ceddf35..b64376d10 100644 --- a/ee/scripts/helm/db/init_dbs/postgresql/init_schema.sql +++ b/ee/scripts/helm/db/init_dbs/postgresql/init_schema.sql @@ -7,7 +7,7 @@ CREATE EXTENSION IF NOT EXISTS pgcrypto; CREATE OR REPLACE FUNCTION openreplay_version() RETURNS text AS $$ -SELECT 'v1.5.1-ee' +SELECT 'v1.5.2-ee' $$ LANGUAGE sql IMMUTABLE; diff --git a/scripts/helm/db/init_dbs/postgresql/1.5.2/1.5.2.sql b/scripts/helm/db/init_dbs/postgresql/1.5.2/1.5.2.sql new file mode 100644 index 000000000..f4e26f93a --- /dev/null +++ b/scripts/helm/db/init_dbs/postgresql/1.5.2/1.5.2.sql @@ -0,0 +1,8 @@ +BEGIN; +CREATE OR REPLACE FUNCTION openreplay_version() + RETURNS text AS +$$ +SELECT 'v1.5.2' +$$ LANGUAGE sql IMMUTABLE; + +COMMIT; \ No newline at end of file diff --git a/scripts/helm/db/init_dbs/postgresql/init_schema.sql b/scripts/helm/db/init_dbs/postgresql/init_schema.sql index 3d05795e9..e053063c2 100644 --- a/scripts/helm/db/init_dbs/postgresql/init_schema.sql +++ b/scripts/helm/db/init_dbs/postgresql/init_schema.sql @@ -6,7 +6,7 @@ CREATE SCHEMA IF NOT EXISTS events; CREATE OR REPLACE FUNCTION openreplay_version() RETURNS text AS $$ -SELECT 'v1.5.1' +SELECT 'v1.5.2' $$ LANGUAGE sql IMMUTABLE; -- --- accounts.sql ---