diff --git a/website/common/tests/test_pages.py b/website/common/tests/test_pages.py index be4fb8b..7247221 100644 --- a/website/common/tests/test_pages.py +++ b/website/common/tests/test_pages.py @@ -60,6 +60,8 @@ class ListingPageTestCase(TestCase): def test_feed_accessible(self) -> None: with self.assertNumQueries(11): - response = self.client.get(self.page.url + self.page.reverse_subpage("feed")) + response = self.client.get( + self.page.url + self.page.reverse_subpage("feed") + ) self.assertEqual(response.status_code, 200) self.assertEqual(response["Content-Type"], "application/rss+xml; charset=utf-8") diff --git a/website/spotify/management/commands/refresh_spotify_playlists.py b/website/spotify/management/commands/refresh_spotify_playlists.py new file mode 100644 index 0000000..8e6ca0a --- /dev/null +++ b/website/spotify/management/commands/refresh_spotify_playlists.py @@ -0,0 +1,17 @@ +from django.core.cache import cache +from django.core.management.base import BaseCommand + +from website.spotify.models import SpotifyPlaylistPage +from website.utils.queue import enqueue_or_sync + + +def refresh_cache(page_id: int) -> None: + page = SpotifyPlaylistPage.objects.get(id=page_id) + cache.delete(page.playlist_cache_key) + page.playlist_data # Prime cache + + +class Command(BaseCommand): + def handle(self, *args: list, **options: dict) -> None: + for page in SpotifyPlaylistPage.objects.all().defer_streamfields().iterator(): + enqueue_or_sync(refresh_cache, args=[page.id])