openreplay/api/chalicelib/core/scope.py
Kraiem Taha Yassine 8c54a74f04
Dev (#2473)
* 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(DB): enhanced top-events caching

* feat(DB): support OR scope
feat(chalice): support OR scope
2024-08-08 17:15:51 +02:00

27 lines
850 B
Python

from cachetools import cached, TTLCache
import schemas
from chalicelib.utils import helper
from chalicelib.utils import pg_client
cache = TTLCache(maxsize=1, ttl=24 * 60 * 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;""")
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;""",
{"scope": scope})
cur.execute(query)
if tenant_id in cache:
cache.pop(tenant_id)
return scope