diff --git a/common/osu/beatmap_provider.py b/common/osu/beatmap_provider.py index c918283..88b9ca3 100644 --- a/common/osu/beatmap_provider.py +++ b/common/osu/beatmap_provider.py @@ -16,6 +16,10 @@ class AbstractBeatmapProvider(ABC): def get_beatmap_file(self, beatmap_id: str) -> str: raise NotImplementedError() + @abstractmethod + def delete_beatmap(self, beatmap_id: str): + raise NotImplementedError() + class LiveBeatmapProvider(AbstractBeatmapProvider): def get_beatmap_file(self, beatmap_id: str) -> str: @@ -32,6 +36,11 @@ def get_beatmap_file(self, beatmap_id: str) -> str: return beatmap_path + def delete_beatmap(self, beatmap_id: str): + beatmap_path = os.path.join(settings.BEATMAP_CACHE_PATH, f"{beatmap_id}.osu") + if os.path.isfile(beatmap_path): + os.remove(beatmap_path) + class StubBeatmapProvider(AbstractBeatmapProvider): def get_beatmap_file(self, beatmap_id: str) -> str: @@ -49,6 +58,9 @@ def get_beatmap_file(self, beatmap_id: str) -> str: return beatmap_path + def delete_beatmap(self, beatmap_id: str): + pass + BeatmapProvider: Type[AbstractBeatmapProvider] = import_string( settings.BEATMAP_PROVIDER_CLASS diff --git a/profiles/management/commands/recalculate.py b/profiles/management/commands/recalculate.py index 18b8312..574f5c0 100644 --- a/profiles/management/commands/recalculate.py +++ b/profiles/management/commands/recalculate.py @@ -346,7 +346,7 @@ def recalculate_scores_v2( initial=initial, smoothing=0, ) as pbar: - for unique_beatmap in unique_beatmaps: + for unique_beatmap in tqdm(unique_beatmaps, desc="Unique beatmaps"): unique_beatmap_scores = scores_to_recalculate.filter( beatmap_id=unique_beatmap["beatmap_id"], mods=unique_beatmap["mods"] ) diff --git a/profiles/tasks.py b/profiles/tasks.py index 5624d33..4070fe3 100644 --- a/profiles/tasks.py +++ b/profiles/tasks.py @@ -3,6 +3,7 @@ from celery import shared_task +from common.osu.beatmap_provider import BeatmapProvider from common.osu.enums import BeatmapStatus, Gamemode from leaderboards.models import Leaderboard from leaderboards.tasks import update_memberships @@ -91,6 +92,8 @@ def update_loved_beatmaps(): f"Beatmap {beatmap.id} appears to have been unloved. Deleting..." ) beatmap.delete() + beatmap_provider = BeatmapProvider() + beatmap_provider.delete_beatmap(str(beatmap.id)) return None outdated_scores = updated_beatmap.scores.filter(