From f4b781912bded10689279788bba03e4fc0733e81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= <40151420+ldericher@users.noreply.github.com> Date: Tue, 6 Sep 2022 22:45:23 +0000 Subject: [PATCH] get_ttl_hash without param --- api/ovdashboard_api/async_helpers.py | 6 ++++-- api/ovdashboard_api/dav_calendar.py | 4 ++-- api/ovdashboard_api/dav_file.py | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/api/ovdashboard_api/async_helpers.py b/api/ovdashboard_api/async_helpers.py index a4a7ef9..82677df 100644 --- a/api/ovdashboard_api/async_helpers.py +++ b/api/ovdashboard_api/async_helpers.py @@ -8,6 +8,8 @@ from time import time from async_lru import alru_cache +from .settings import SETTINGS + def run_in_executor(f): """ @@ -27,13 +29,13 @@ def run_in_executor(f): return wrapper -def get_ttl_hash(seconds: int = 20) -> int: +def get_ttl_hash() -> int: """ Return the same value within `seconds` time period. https://stackoverflow.com/a/55900800 """ - return round(time() / seconds) + return round(time() / SETTINGS.cache_seconds) def timed_alru_cache(*decorator_args, **decorator_kwargs): diff --git a/api/ovdashboard_api/dav_calendar.py b/api/ovdashboard_api/dav_calendar.py index 6af3d17..dc7a713 100644 --- a/api/ovdashboard_api/dav_calendar.py +++ b/api/ovdashboard_api/dav_calendar.py @@ -183,7 +183,7 @@ class DavCalendar: """ return await _get_calendar( - ttl_hash=get_ttl_hash(SETTINGS.cache_seconds), + ttl_hash=get_ttl_hash(), calendar_name=self.calendar_name, ) @@ -194,6 +194,6 @@ class DavCalendar: """ return await _get_calendar_events( - ttl_hash=get_ttl_hash(SETTINGS.cache_seconds), + ttl_hash=get_ttl_hash(), calendar_name=self.calendar_name, ) diff --git a/api/ovdashboard_api/dav_file.py b/api/ovdashboard_api/dav_file.py index c6a532b..4ba7022 100644 --- a/api/ovdashboard_api/dav_file.py +++ b/api/ovdashboard_api/dav_file.py @@ -61,7 +61,7 @@ class DavFile: """ return await _get_buffer( - ttl_hash=get_ttl_hash(SETTINGS.cache_seconds), + ttl_hash=get_ttl_hash(), remote_path=self.remote_path, )