* 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 update scope for EE
28 lines
960 B
Python
28 lines
960 B
Python
from cachetools import cached, TTLCache
|
|
|
|
from chalicelib.utils import pg_client
|
|
|
|
cache = TTLCache(maxsize=1000, ttl=60)
|
|
|
|
|
|
@cached(cache)
|
|
def get_scope(tenant_id) -> int:
|
|
with pg_client.PostgresClient() as cur:
|
|
query = cur.mogrify(f"""SELECT scope_state
|
|
FROM public.tenants
|
|
WHERE tenant_id=%(tenant_id)s;""",
|
|
{"tenant_id": tenant_id})
|
|
cur.execute(query)
|
|
return cur.fetchone()["scope_state"]
|
|
|
|
|
|
def update_scope(tenant_id, scope: int):
|
|
with pg_client.PostgresClient() as cur:
|
|
query = cur.mogrify(f"""UPDATE public.tenants
|
|
SET scope_state = %(scope_state)s
|
|
WHERE tenant_id=%(tenant_id)s;""",
|
|
{"scope_state": scope, "tenant_id": tenant_id})
|
|
cur.execute(query)
|
|
if tenant_id in cache:
|
|
cache.pop(tenant_id)
|
|
return scope
|