Proper caching of player history

This commit is contained in:
Maximilian Keßler 2023-11-24 13:14:01 +01:00
parent 94d698ad14
commit 613bb108a7
Signed by: max
GPG key ID: BCC5A619923C0BA5
2 changed files with 9 additions and 4 deletions

View file

@ -41,5 +41,6 @@ FORBIDDEN_GAME_OPTIONS = [
, "detrimentalCharacters" , "detrimentalCharacters"
] ]
# Cache time in secodn # Cache time (in seconds) for history requests of players
USER_HISTORY_CACHE_TIME = 5 # In case of frequent reruns (especially during development), we do not want to stress the server too much.
USER_HISTORY_CACHE_TIME = 5 * 60

View file

@ -19,13 +19,17 @@ from config import config_manager
# This ensures that we do not pose too many requests to the website, especially while in development where we # This ensures that we do not pose too many requests to the website, especially while in development where we
# might frequently re-initialize the database. # might frequently re-initialize the database.
session = requests_cache.CachedSession( session = requests_cache.CachedSession(
platformdirs.user_cache_dir(constants.APP_NAME) + 'hanab.live.requests-cache', platformdirs.user_cache_dir(constants.APP_NAME) + '/hanab.live.requests-cache',
urls_expire_after={ urls_expire_after={
# Game exports will never change, so cache them forever # Game exports will never change, so cache them forever
'hanab.live/export/*': requests_cache.NEVER_EXPIRE 'hanab.live/export/*': requests_cache.NEVER_EXPIRE,
# Cash history requests for 5 minutes, this seems like a reasonable time
'hanab.live/api/v1/history-full/*': constants.USER_HISTORY_CACHE_TIME
} }
) )
print(platformdirs.user_cache_dir(constants.APP_NAME) + 'hanab.live.requests-cache')
class GameInfo: class GameInfo:
def __init__(self, game_id: int, num_players: int, variant_id: int, seed: str, score: int, num_turns: int, def __init__(self, game_id: int, num_players: int, variant_id: int, seed: str, score: int, num_turns: int,