diff --git a/bemani/common/time.py b/bemani/common/time.py index affd54b..be5d317 100644 --- a/bemani/common/time.py +++ b/bemani/common/time.py @@ -12,6 +12,7 @@ class Time: standard unix timestamps at UTC timezone given various parameters. """ + SECONDS_IN_SECOND: Final[int] = 1 SECONDS_IN_MINUTE: Final[int] = 60 SECONDS_IN_HOUR: Final[int] = 3600 SECONDS_IN_DAY: Final[int] = 86400 diff --git a/bemani/data/api/client.py b/bemani/data/api/client.py index 2a5cb54..ae766e7 100644 --- a/bemani/data/api/client.py +++ b/bemani/data/api/client.py @@ -9,6 +9,8 @@ from bemani.common import ( VersionConstants, DBConstants, ValidatedDict, + Time, + cache, ) @@ -228,6 +230,8 @@ class APIClient: return (servergame, serverversion) + # Not caching this, as it is only hit when looking at the admin panel, and we want this to + # always be up-to-date. def get_server_info(self) -> ValidatedDict: resp = self.__exchange_data("", {}) return ValidatedDict( @@ -238,6 +242,9 @@ class APIClient: } ) + # Not caching this, as we would have to go back and ensure that any code which got outdated + # profiles from a cache didn't end up with KeyError exceptions when trying to link profiles to + # records. This is the coward's way out, but whatever. def get_profiles( self, game: GameConstants, version: int, idtype: APIConstants, ids: List[str] ) -> List[Dict[str, Any]]: @@ -260,6 +267,7 @@ class APIClient: # Couldn't talk to server, assume empty profiles return [] + @cache.memoize(Time.SECONDS_IN_MINUTE * 1) def get_records( self, game: GameConstants, @@ -293,6 +301,7 @@ class APIClient: # Couldn't talk to server, assume empty records return [] + @cache.memoize(Time.SECONDS_IN_MINUTE * 5) def get_statistics( self, game: GameConstants, version: int, idtype: APIConstants, ids: List[str] ) -> List[Dict[str, Any]]: @@ -315,6 +324,7 @@ class APIClient: # Couldn't talk to server, assume empty statistics return [] + @cache.memoize(Time.SECONDS_IN_HOUR * 1) def get_catalog( self, game: GameConstants, version: int ) -> Dict[str, List[Dict[str, Any]]]: