* fix(chalice): fixed Math-operators validation
refactor(chalice): search for sessions that have events for heatmaps

* refactor(chalice): search for sessions that have at least 1 location event for heatmaps

* fix(chalice): fixed Math-operators validation
refactor(chalice): search for sessions that have events for heatmaps

* refactor(chalice): search for sessions that have at least 1 location event for heatmaps

* feat(chalice): autocomplete return top 10 with stats

* fix(chalice): fixed autocomplete top 10 meta-filters

* fix(chalice): fixed table of fetch-users for EE

* fix(chalice): foss vs saas response discrepancy for table of referrers

* fix(DB): fixed scope_state delta
This commit is contained in:
Kraiem Taha Yassine 2024-09-11 18:12:41 +02:00 committed by GitHub
parent 7829a2e2f2
commit 2253ac394d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 52 additions and 45 deletions

View file

@ -457,25 +457,26 @@ def search2_table(data: schemas.SessionsSearchPayloadSchema, project_id: int, de
if metric_format == schemas.MetricExtendedFormatType.SESSION_COUNT:
main_query = f"""SELECT COUNT(DISTINCT {main_col}) OVER () AS main_count,
{main_col} AS name,
count(DISTINCT session_id) AS session_count,
COALESCE(SUM(count(DISTINCT session_id)) OVER (), 0) AS total_sessions
count(DISTINCT session_id) AS total,
COALESCE(SUM(count(DISTINCT session_id)) OVER (), 0) AS total_count
FROM (SELECT s.session_id AS session_id {extra_col}
{query_part}) AS filtred_sessions
{extra_where}
GROUP BY {main_col}
ORDER BY session_count DESC
ORDER BY total_count DESC
LIMIT %(limit_e)s OFFSET %(limit_s)s;"""
else:
main_query = f"""SELECT COUNT(DISTINCT {main_col}) OVER () AS main_count,
{main_col} AS name,
count(DISTINCT user_id) AS user_count
count(DISTINCT user_id) AS total,
COALESCE(SUM(count(DISTINCT user_id)) OVER (), 0) AS total_count
FROM (SELECT s.user_id AS user_id {extra_col}
{query_part}
WHERE isNotNull(user_id)
AND user_id != '') AS filtred_sessions
{extra_where}
GROUP BY {main_col}
ORDER BY user_count DESC
ORDER BY total_count DESC
LIMIT %(limit_e)s OFFSET %(limit_s)s;"""
main_query = cur.format(main_query, full_args)
@ -484,14 +485,14 @@ def search2_table(data: schemas.SessionsSearchPayloadSchema, project_id: int, de
logging.debug("--------------------")
sessions = cur.execute(main_query)
count = 0
total_sessions = 0
total = 0
if len(sessions) > 0:
count = sessions[0]["main_count"]
total_sessions = sessions[0]["total_sessions"]
total = sessions[0]["total_count"]
for s in sessions:
s.pop("main_count")
s.pop("total_sessions")
sessions = {"total": count, "count": total_sessions, "values": helper.list_to_camel_case(sessions)}
s.pop("total_count")
sessions = {"total": count, "count": total, "values": helper.list_to_camel_case(sessions)}
return sessions

View file

@ -53,6 +53,9 @@ CREATE TABLE IF NOT EXISTS or_cache.autocomplete_top_values
ALTER TABLE IF EXISTS public.tenants
ADD COLUMN IF NOT EXISTS scope_state smallint NOT NULL DEFAULT 2;
ALTER TABLE IF EXISTS public.tenants
ALTER COLUMN scope_state SET DEFAULT 0;
ALTER TABLE IF EXISTS public.users
ALTER COLUMN settings SET DEFAULT '{
"modules": [
@ -65,25 +68,25 @@ CREATE SCHEMA IF NOT EXISTS spots;
CREATE TABLE IF NOT EXISTS spots.spots
(
spot_id BIGINT NOT NULL PRIMARY KEY,
name TEXT NOT NULL,
user_id BIGINT NOT NULL REFERENCES public.users (user_id) ON DELETE CASCADE,
tenant_id BIGINT NOT NULL REFERENCES public.tenants (tenant_id) ON DELETE CASCADE,
duration INT NOT NULL,
spot_id BIGINT NOT NULL PRIMARY KEY,
name TEXT NOT NULL,
user_id BIGINT NOT NULL REFERENCES public.users (user_id) ON DELETE CASCADE,
tenant_id BIGINT NOT NULL REFERENCES public.tenants (tenant_id) ON DELETE CASCADE,
duration INT NOT NULL,
crop INT[],
comments TEXT[],
status TEXT DEFAULT 'pending',
status TEXT DEFAULT 'pending',
created_at timestamp without time zone NOT NULL DEFAULT timezone('utc'::text, now()),
updated_at timestamp DEFAULT NULL,
deleted_at timestamp DEFAULT NULL
updated_at timestamp DEFAULT NULL,
deleted_at timestamp DEFAULT NULL
);
CREATE TABLE IF NOT EXISTS spots.keys
(
spot_key TEXT NOT NULL PRIMARY KEY,
spot_id BIGINT NOT NULL UNIQUE REFERENCES spots.spots (spot_id) ON DELETE CASCADE,
user_id BIGINT NOT NULL,
expiration BIGINT NOT NULL,
spot_key TEXT NOT NULL PRIMARY KEY,
spot_id BIGINT NOT NULL UNIQUE REFERENCES spots.spots (spot_id) ON DELETE CASCADE,
user_id BIGINT NOT NULL,
expiration BIGINT NOT NULL,
expired_at timestamp NOT NULL,
created_at timestamp NOT NULL,
updated_at timestamp DEFAULT NULL
@ -91,19 +94,19 @@ CREATE TABLE IF NOT EXISTS spots.keys
CREATE TABLE IF NOT EXISTS spots.streams
(
spot_id BIGINT NOT NULL PRIMARY KEY REFERENCES spots.spots (spot_id) ON DELETE CASCADE,
original_playlist TEXT NOT NULL,
modified_playlist TEXT NOT NULL,
spot_id BIGINT NOT NULL PRIMARY KEY REFERENCES spots.spots (spot_id) ON DELETE CASCADE,
original_playlist TEXT NOT NULL,
modified_playlist TEXT NOT NULL,
created_at timestamp NOT NULL,
expired_at timestamp NOT NULL
);
CREATE TABLE IF NOT EXISTS spots.tasks
(
spot_id BIGINT NOT NULL PRIMARY KEY REFERENCES spots.spots (spot_id) ON DELETE CASCADE,
duration INT NOT NULL,
spot_id BIGINT NOT NULL PRIMARY KEY REFERENCES spots.spots (spot_id) ON DELETE CASCADE,
duration INT NOT NULL,
crop INT[],
status TEXT NOT NULL,
status TEXT NOT NULL,
error TEXT DEFAULT NULL,
added_time timestamp NOT NULL
);

View file

@ -42,6 +42,9 @@ CREATE TABLE IF NOT EXISTS or_cache.autocomplete_top_values
ALTER TABLE IF EXISTS public.tenants
ADD COLUMN IF NOT EXISTS scope_state smallint NOT NULL DEFAULT 2;
ALTER TABLE IF EXISTS public.tenants
ALTER COLUMN scope_state SET DEFAULT 0;
ALTER TABLE IF EXISTS public.users
ALTER COLUMN settings SET DEFAULT '{
"modules": [
@ -54,25 +57,25 @@ CREATE SCHEMA IF NOT EXISTS spots;
CREATE TABLE IF NOT EXISTS spots.spots
(
spot_id BIGINT NOT NULL PRIMARY KEY,
name TEXT NOT NULL,
user_id BIGINT NOT NULL REFERENCES public.users (user_id) ON DELETE CASCADE,
tenant_id BIGINT NOT NULL,
duration INT NOT NULL,
spot_id BIGINT NOT NULL PRIMARY KEY,
name TEXT NOT NULL,
user_id BIGINT NOT NULL REFERENCES public.users (user_id) ON DELETE CASCADE,
tenant_id BIGINT NOT NULL,
duration INT NOT NULL,
crop INT[],
comments TEXT[],
status TEXT DEFAULT 'pending',
status TEXT DEFAULT 'pending',
created_at timestamp without time zone NOT NULL DEFAULT timezone('utc'::text, now()),
updated_at timestamp DEFAULT NULL,
deleted_at timestamp DEFAULT NULL
updated_at timestamp DEFAULT NULL,
deleted_at timestamp DEFAULT NULL
);
CREATE TABLE IF NOT EXISTS spots.keys
(
spot_key TEXT NOT NULL PRIMARY KEY,
spot_id BIGINT NOT NULL UNIQUE REFERENCES spots.spots (spot_id) ON DELETE CASCADE,
user_id BIGINT NOT NULL,
expiration BIGINT NOT NULL,
spot_key TEXT NOT NULL PRIMARY KEY,
spot_id BIGINT NOT NULL UNIQUE REFERENCES spots.spots (spot_id) ON DELETE CASCADE,
user_id BIGINT NOT NULL,
expiration BIGINT NOT NULL,
expired_at timestamp NOT NULL,
created_at timestamp NOT NULL,
updated_at timestamp DEFAULT NULL
@ -80,19 +83,19 @@ CREATE TABLE IF NOT EXISTS spots.keys
CREATE TABLE IF NOT EXISTS spots.streams
(
spot_id BIGINT NOT NULL PRIMARY KEY REFERENCES spots.spots (spot_id) ON DELETE CASCADE,
original_playlist TEXT NOT NULL,
modified_playlist TEXT NOT NULL,
spot_id BIGINT NOT NULL PRIMARY KEY REFERENCES spots.spots (spot_id) ON DELETE CASCADE,
original_playlist TEXT NOT NULL,
modified_playlist TEXT NOT NULL,
created_at timestamp NOT NULL,
expired_at timestamp NOT NULL
);
CREATE TABLE IF NOT EXISTS spots.tasks
(
spot_id BIGINT NOT NULL PRIMARY KEY REFERENCES spots.spots (spot_id) ON DELETE CASCADE,
duration INT NOT NULL,
spot_id BIGINT NOT NULL PRIMARY KEY REFERENCES spots.spots (spot_id) ON DELETE CASCADE,
duration INT NOT NULL,
crop INT[],
status TEXT NOT NULL,
status TEXT NOT NULL,
error TEXT DEFAULT NULL,
added_time timestamp NOT NULL
);