Add management command to refresh caches of spotify playlists
This commit is contained in:
parent
2b0779b26a
commit
3d155bb46f
2 changed files with 20 additions and 1 deletions
|
@ -60,6 +60,8 @@ class ListingPageTestCase(TestCase):
|
||||||
|
|
||||||
def test_feed_accessible(self) -> None:
|
def test_feed_accessible(self) -> None:
|
||||||
with self.assertNumQueries(11):
|
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.status_code, 200)
|
||||||
self.assertEqual(response["Content-Type"], "application/rss+xml; charset=utf-8")
|
self.assertEqual(response["Content-Type"], "application/rss+xml; charset=utf-8")
|
||||||
|
|
|
@ -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])
|
Loading…
Reference in a new issue