Skip to content

Commit

Permalink
Merge pull request #66 from Syriiin/fix/delete-unloved-beatmap-file
Browse files Browse the repository at this point in the history
Delete unloved beatmap files along with db rows
  • Loading branch information
Syriiin authored Jun 3, 2024
2 parents bde723e + 9d25f50 commit a2b8579
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
12 changes: 12 additions & 0 deletions common/osu/beatmap_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion profiles/management/commands/recalculate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
)
Expand Down
3 changes: 3 additions & 0 deletions profiles/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit a2b8579

Please sign in to comment.