diff --git a/docker-compose.yml b/docker-compose.yml index 9c7f45e..cb5cf0c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -16,6 +16,7 @@ services: - ./data/db:/var/lib/postgresql/data env_file: - config/active/postgres.env + shm_size: 128m queue: image: rabbitmq:3-management diff --git a/leaderboards/tasks.py b/leaderboards/tasks.py index 6183756..aac1271 100644 --- a/leaderboards/tasks.py +++ b/leaderboards/tasks.py @@ -115,18 +115,25 @@ def send_notification( @shared_task -def update_global_leaderboard_top_5_score_cache(): +def dispatch_update_global_leaderboard_top_5_score_cache(): for gamemode in Gamemode: leaderboards = Leaderboard.objects.filter( access_type=LeaderboardAccessType.GLOBAL, gamemode=gamemode ) for leaderboard in leaderboards: - scores = leaderboard.get_top_scores(limit=5) - cache.set( - f"leaderboards::global_leaderboard_top_5_scores::{leaderboard.id}", - scores, - 1800, - ) + update_global_leaderboard_top_5_score_cache.delay(leaderboard.id) + + +@shared_task +def update_global_leaderboard_top_5_score_cache(leaderboard_id: int): + leaderboard = Leaderboard.objects.get(id=leaderboard_id) + scores = leaderboard.get_top_scores(limit=5) + cache.set( + f"leaderboards::global_leaderboard_top_5_scores::{leaderboard.id}", + scores, + 1800, + ) + return scores @shared_task diff --git a/osuchan/settings.py b/osuchan/settings.py index 1914ab7..f6fdfc2 100644 --- a/osuchan/settings.py +++ b/osuchan/settings.py @@ -201,7 +201,7 @@ class EnvSettings(BaseSettings): "schedule": crontab(minute=0, hour=0), # midnight UTC }, "update-global-leaderboard-top-5-score-cache-every-20-minutes": { - "task": "leaderboards.tasks.update_global_leaderboard_top_5_score_cache", + "task": "leaderboards.tasks.dispatch_update_global_leaderboard_top_5_score_cache", "schedule": crontab(minute="*/20"), }, }