website/website/spotify/management/commands/refresh_spotify_playlists.py

23 lines
633 B
Python
Raw Permalink Normal View History

from django.core.cache import cache
from django.core.management.base import BaseCommand
2024-06-08 12:52:52 +01:00
from django_tasks import task
from website.spotify.models import SpotifyPlaylistPage
2024-06-08 12:52:52 +01:00
@task()
def refresh_cache(page_id: int) -> None:
page = SpotifyPlaylistPage.objects.get(id=page_id)
cache.delete(page.playlist_cache_key)
2023-07-15 15:10:05 +01:00
# Prime cache
page.playlist_data # noqa: B018
class Command(BaseCommand):
def handle(self, *args: list, **options: dict) -> None:
2024-06-08 12:52:52 +01:00
for page_id in (
SpotifyPlaylistPage.objects.all().values_list("id", flat=True).iterator()
):
refresh_cache.enqueue(page_id)