Skip to content

Commit

Permalink
Remove global leaderboard top score cache and task
Browse files Browse the repository at this point in the history
  • Loading branch information
Syriiin committed Jun 2, 2024
1 parent af2e651 commit bcc95dc
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 35 deletions.
22 changes: 0 additions & 22 deletions leaderboards/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,6 @@ def update_memberships(user_id, gamemode=Gamemode.STANDARD):
return memberships


@shared_task
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:
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,
7200,
)
return scores


@shared_task
def send_leaderboard_top_score_notification(leaderboard_id: int, score_id: int):
# passing score_id instead of querying for top score in case it changes before the job is picked up
Expand Down
9 changes: 1 addition & 8 deletions leaderboards/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,14 +284,7 @@ def get(self, request, leaderboard_type, gamemode, leaderboard_id):
except Leaderboard.DoesNotExist:
raise NotFound("Leaderboard not found.")

if leaderboard.access_type == LeaderboardAccessType.GLOBAL:
scores = cache.get_or_set(
f"leaderboards::global_leaderboard_top_5_scores::{leaderboard.id}",
lambda: leaderboard.get_top_scores(limit=limit),
7200,
)
else:
scores = leaderboard.get_top_scores(limit=limit)
scores = leaderboard.get_top_scores(limit=limit)

serialiser = LeaderboardScoreSerialiser(scores, many=True)
return Response(serialiser.data)
Expand Down
4 changes: 0 additions & 4 deletions osuchan/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,6 @@ class EnvSettings(BaseSettings):
"cooldown_seconds": timedelta(hours=12).total_seconds(),
},
},
"update-global-leaderboard-top-5-score-cache-every-hour": {
"task": "leaderboards.tasks.dispatch_update_global_leaderboard_top_5_score_cache",
"schedule": crontab(minute="0"),
},
"update-loved-beatmaps-every-month": {
"task": "profiles.tasks.update_loved_beatmaps",
"schedule": crontab(minute="0", hour="0", day_of_month="1"),
Expand Down
1 change: 0 additions & 1 deletion profiles/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from common.osu.difficultycalculator import Score as DifficultyCalculatorScore
from common.osu.enums import BeatmapStatus, Gamemode, Mods
from leaderboards.models import Leaderboard, Membership
from leaderboards.tasks import update_memberships
from profiles.models import (
Beatmap,
DifficultyCalculation,
Expand Down

0 comments on commit bcc95dc

Please sign in to comment.