Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split global leaderboard score cache task #34

Merged
merged 2 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 14 additions & 7 deletions leaderboards/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion osuchan/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
},
}
Expand Down
Loading