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