* 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

* refactor(chalice): changed scope to scopeState with 0|1|2 values
This commit is contained in:
Kraiem Taha Yassine 2024-09-02 18:05:22 +02:00 committed by GitHub
parent 70e2d62de9
commit cbf389f6f9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 19 additions and 26 deletions

View file

@ -1,6 +1,5 @@
from cachetools import cached, TTLCache
import schemas
from chalicelib.utils import helper
from chalicelib.utils import pg_client
@ -8,19 +7,19 @@ cache = TTLCache(maxsize=1, ttl=60)
@cached(cache)
def get_scope(tenant_id) -> schemas.ScopeType:
def get_scope(tenant_id) -> int:
with pg_client.PostgresClient() as cur:
query = cur.mogrify(f"""SELECT scope
query = cur.mogrify(f"""SELECT scope_state
FROM public.tenants;""")
cur.execute(query)
return helper.dict_to_camel_case(cur.fetchone())["scope"]
return helper.dict_to_camel_case(cur.fetchone())["scope_state"]
def update_scope(tenant_id, scope: schemas.ScopeType):
def update_scope(tenant_id, scope: int):
with pg_client.PostgresClient() as cur:
query = cur.mogrify(f"""UPDATE public.tenants
SET scope = %(scope)s;""",
{"scope": scope})
SET scope_state = %(scope_state)s;""",
{"scope_state": scope})
cur.execute(query)
if tenant_id in cache:
cache.pop(tenant_id)

View file

@ -77,7 +77,7 @@ def login_user(response: JSONResponse, spot: Optional[bool] = False, data: schem
'jwt': r.pop('jwt'),
'data': {
"user": r,
"scope": scope.get_scope(-1)
"scopeState": scope.get_scope(-1)
}
}
response.set_cookie(key="refreshToken", value=refresh_token, path=COOKIE_PATH,

View file

@ -1687,10 +1687,5 @@ class TagCreate(TagUpdate):
ignoreDeadClick: bool = Field(default=False)
class ScopeType(str, Enum):
FULL_OR = "full"
SPOT_ONLY = "spot"
class ScopeSchema(BaseModel):
scope: ScopeType = Field(default=ScopeType.FULL_OR)
scope: int = Field(default=1, ge=1, le=2)

View file

@ -1,6 +1,5 @@
from cachetools import cached, TTLCache
import schemas
from chalicelib.utils import helper
from chalicelib.utils import pg_client
@ -8,22 +7,22 @@ cache = TTLCache(maxsize=1000, ttl=60)
@cached(cache)
def get_scope(tenant_id) -> schemas.ScopeType:
def get_scope(tenant_id) -> int:
with pg_client.PostgresClient() as cur:
query = cur.mogrify(f"""SELECT scope
query = cur.mogrify(f"""SELECT scope_state
FROM public.tenants
WHERE tenant_id=%(tenant_id)s;""",
{"tenant_id": tenant_id})
cur.execute(query)
return helper.dict_to_camel_case(cur.fetchone())["scope"]
return helper.dict_to_camel_case(cur.fetchone())["scope_state"]
def update_scope(tenant_id, scope: schemas.ScopeType):
def update_scope(tenant_id, scope: int):
with pg_client.PostgresClient() as cur:
query = cur.mogrify(f"""UPDATE public.tenants
SET scope = %(scope)s
SET scope_state = %(scope_state)s
WHERE tenant_id=%(tenant_id)s;""",
{"scope": scope, "tenant_id": tenant_id})
{"scope_state": scope, "tenant_id": tenant_id})
cur.execute(query)
if tenant_id in cache:
cache.pop(tenant_id)

View file

@ -81,7 +81,7 @@ def login_user(response: JSONResponse, spot: Optional[bool] = False, data: schem
content = {
'jwt': r.pop('jwt'),
'data': {
"scope": scope.get_scope(r["tenantId"]),
"scopeState": scope.get_scope(r["tenantId"]),
"user": r
}
}

View file

@ -51,7 +51,7 @@ CREATE TABLE IF NOT EXISTS or_cache.autocomplete_top_values
);
ALTER TABLE IF EXISTS public.tenants
ADD COLUMN IF NOT EXISTS scope text NOT NULL DEFAULT 'full';
ADD COLUMN IF NOT EXISTS scope_state smallint NOT NULL DEFAULT 2;
COMMIT;

View file

@ -105,7 +105,7 @@ CREATE TABLE public.tenants
t_users integer NOT NULL DEFAULT 1,
t_integrations integer NOT NULL DEFAULT 0,
last_telemetry bigint NOT NULL DEFAULT CAST(EXTRACT(epoch FROM date_trunc('day', now())) * 1000 AS BIGINT),
scope text NOT NULL DEFAULT 'full'
scope_state smallint NOT NULL DEFAULT 0
);

View file

@ -40,7 +40,7 @@ CREATE TABLE IF NOT EXISTS or_cache.autocomplete_top_values
);
ALTER TABLE IF EXISTS public.tenants
ADD COLUMN IF NOT EXISTS scope text NOT NULL DEFAULT 'full';
ADD COLUMN IF NOT EXISTS scope_state smallint NOT NULL DEFAULT 2;
COMMIT;

View file

@ -104,7 +104,7 @@ CREATE TABLE public.tenants
t_users integer NOT NULL DEFAULT 1,
t_integrations integer NOT NULL DEFAULT 0,
last_telemetry bigint NOT NULL DEFAULT CAST(EXTRACT(epoch FROM date_trunc('day', now())) * 1000 AS BIGINT),
scope text NOT NULL DEFAULT 'full',
scope_state smallint NOT NULL DEFAULT 0,
CONSTRAINT onerow_uni CHECK (tenant_id = 1)
);