Skip to content

Commit

Permalink
Remove caching for config
Browse files Browse the repository at this point in the history
Otherwise, this introduces issues of coroutine that are reused
  • Loading branch information
aranega committed Oct 12, 2024
1 parent 5272ca0 commit 4eff509
Showing 1 changed file with 0 additions and 18 deletions.
18 changes: 0 additions & 18 deletions applications/visualizer/backend/api/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import time
from functools import lru_cache, partial, update_wrapper
from django.utils.functional import lazy
from django.conf import settings

from .schemas import EMData
Expand All @@ -12,21 +9,6 @@ async def to_list(q):
return [x async for x in q]


def lru_cache_time(seconds, maxsize=None):
def wrapper(func):
# Lazy function that makes sure the lru_cache() invalidate after X secs
ttl_hash = lazy(lambda: round(time.time() / seconds), int)()

@lru_cache(maxsize)
def time_aware(__ttl, *args, **kwargs):
return func(*args, **kwargs)

return update_wrapper(partial(time_aware, ttl_hash), func)

return wrapper


@lru_cache_time(seconds=60 * 60, maxsize=10) # We cache information for 1h
async def get_dataset_viewer_config(dataset: Dataset):
config = await dataset.config.afirst() # type: ignore
if config is None:
Expand Down

0 comments on commit 4eff509

Please sign in to comment.