Skip to content

Commit

Permalink
Delete unloved beatmap files along with db rows
Browse files Browse the repository at this point in the history
  • Loading branch information
Syriiin committed Jun 3, 2024
1 parent bde723e commit 6912296
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
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
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 6912296

Please sign in to comment.