From bcc95dc14be60291da21906f9dcd9f6c6066e8fb Mon Sep 17 00:00:00 2001 From: Samuel Cattini-Schultz Date: Mon, 3 Jun 2024 02:10:51 +1000 Subject: [PATCH] Remove global leaderboard top score cache and task --- leaderboards/tasks.py | 22 ---------------------- leaderboards/views.py | 9 +-------- osuchan/settings.py | 4 ---- profiles/services.py | 1 - 4 files changed, 1 insertion(+), 35 deletions(-) diff --git a/leaderboards/tasks.py b/leaderboards/tasks.py index 3445100..58a8ec6 100644 --- a/leaderboards/tasks.py +++ b/leaderboards/tasks.py @@ -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 diff --git a/leaderboards/views.py b/leaderboards/views.py index c845dad..f72ed5c 100644 --- a/leaderboards/views.py +++ b/leaderboards/views.py @@ -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) diff --git a/osuchan/settings.py b/osuchan/settings.py index 453650f..2639f23 100644 --- a/osuchan/settings.py +++ b/osuchan/settings.py @@ -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"), diff --git a/profiles/services.py b/profiles/services.py index 6a6a8e1..dbfedf1 100644 --- a/profiles/services.py +++ b/profiles/services.py @@ -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,