[templates] Fix caching issue with Now Playing
This commit is contained in:
@ -1,5 +1,4 @@
|
|||||||
import pytz
|
import pytz
|
||||||
from django.core.cache import cache
|
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
from scrobbles.constants import EXCLUDE_FROM_NOW_PLAYING
|
from scrobbles.constants import EXCLUDE_FROM_NOW_PLAYING
|
||||||
@ -20,8 +19,6 @@ MONTH_COLORS = [
|
|||||||
"#db7a7a", # Dec
|
"#db7a7a", # Dec
|
||||||
]
|
]
|
||||||
|
|
||||||
CACHE_TTL = 60
|
|
||||||
|
|
||||||
|
|
||||||
def month_color(request):
|
def month_color(request):
|
||||||
from datetime import date
|
from datetime import date
|
||||||
@ -33,10 +30,8 @@ def now_playing(request):
|
|||||||
if not user.is_authenticated:
|
if not user.is_authenticated:
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
cache_key = f"now_playing_list_{user.id}"
|
return {
|
||||||
now_playing_list = cache.get(cache_key)
|
"now_playing_list": list(
|
||||||
if now_playing_list is None:
|
|
||||||
now_playing_list = list(
|
|
||||||
Scrobble.objects.filter(
|
Scrobble.objects.filter(
|
||||||
in_progress=True,
|
in_progress=True,
|
||||||
is_paused=False,
|
is_paused=False,
|
||||||
@ -46,9 +41,5 @@ def now_playing(request):
|
|||||||
media_type__in=EXCLUDE_FROM_NOW_PLAYING,
|
media_type__in=EXCLUDE_FROM_NOW_PLAYING,
|
||||||
)
|
)
|
||||||
.select_related("track", "video", "podcast_episode")
|
.select_related("track", "video", "podcast_episode")
|
||||||
)
|
),
|
||||||
cache.set(cache_key, now_playing_list, CACHE_TTL)
|
|
||||||
|
|
||||||
return {
|
|
||||||
"now_playing_list": now_playing_list,
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user