Introduce V2 of current and historical functions

This commit is contained in:
2024-11-03 23:18:06 -08:00
parent 27cd98ee52
commit ff8e182336
21 changed files with 655 additions and 428 deletions

28
wow_token/db/cache.py Normal file
View File

@@ -0,0 +1,28 @@
import datetime
from typing import Dict, List, Tuple
from wow_token.db.cached_range import CachedRange
from wow_token.db.trinity import Trinity
class Cache:
_cache : Dict[str, List[Tuple[datetime.datetime, int]]]
_db : 'Compacted'
def __init__(self, compacted_db: 'Compacted'):
self._db = compacted_db
self._cache = {}
def get_month(self, trinity: Trinity) -> List[Tuple[datetime.datetime, int]]:
current_time = datetime.datetime.now(datetime.UTC)
if isinstance(trinity.range, CachedRange):
raise NotImplementedError
current_month = trinity.range.month == current_time.month and trinity.range.year == current_time.year
if not current_month and str(trinity) in self._cache:
return self._cache[str(trinity)]
self._cache[str(trinity)] = self._db.ddb_get_data(trinity)
return self._cache[str(trinity)]