openreplay/ee/api/chalicelib/core/scope.py
Kraiem Taha Yassine 3e6a1e5468
Dev (#2476)
* refactor(chalice): upgraded dependencies

* refactor(chalice): upgraded dependencies
feat(chalice): support 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

* refactor(chalice): upgraded dependencies

* refactor(chalice): upgraded dependencies
feat(chalice): support 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

* refactor(chalice): upgraded dependencies
refactor(crons): upgraded dependencies
refactor(alerts): upgraded dependencies

* feat(chalice): get top 10 values for autocomplete CH

* refactor(chalice): cleaned code
refactor(chalice): upgraded dependencies
refactor(alerts): upgraded dependencies
refactor(crons): upgraded dependencies

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

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

* refactor(chalice): refactored heath-check package
refactor(chalice): enhanced scope caching
dev(chalice): reduced Spot JWT TTL for testing purposes
2024-08-09 11:50:50 +02:00

30 lines
1 KiB
Python

from cachetools import cached, TTLCache
import schemas
from chalicelib.utils import helper
from chalicelib.utils import pg_client
cache = TTLCache(maxsize=1000, ttl=60)
@cached(cache)
def get_scope(tenant_id) -> schemas.ScopeType:
with pg_client.PostgresClient() as cur:
query = cur.mogrify(f"""SELECT scope
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"]
def update_scope(tenant_id, scope: schemas.ScopeType):
with pg_client.PostgresClient() as cur:
query = cur.mogrify(f"""UPDATE public.tenants
SET scope = %(scope)s
WHERE tenant_id=%(tenant_id)s;""",
{"scope": scope, "tenant_id": tenant_id})
cur.execute(query)
if tenant_id in cache:
cache.pop(tenant_id)
return scope