lint
This commit is contained in:
parent
601144edf8
commit
66e49cb12e
|
@ -125,9 +125,11 @@ class SessionRadio(SimpleRadio):
|
|||
def cache_batch_radio_track(self, **kwargs):
|
||||
BATCH_SIZE = 100
|
||||
# get cached RadioTracks if any
|
||||
try :
|
||||
cached_evaluated_radio_tracks = pickle.loads(cache.get(f"radiosessiontracks{self.session.id}"))
|
||||
except TypeError :
|
||||
try:
|
||||
cached_evaluated_radio_tracks = pickle.loads(
|
||||
cache.get(f"radiosessiontracks{self.session.id}")
|
||||
)
|
||||
except TypeError:
|
||||
cached_evaluated_radio_tracks = None
|
||||
|
||||
# get the queryset and apply filters
|
||||
|
@ -173,8 +175,10 @@ class SessionRadio(SimpleRadio):
|
|||
return queryset
|
||||
|
||||
def get_choices_v2(self, quantity, **kwargs):
|
||||
if cache.get(f"radiosessiontracks{self.session.id}") :
|
||||
cached_radio_tracks = pickle.loads(cache.get(f"radiosessiontracks{self.session.id}"))
|
||||
if cache.get(f"radiosessiontracks{self.session.id}"):
|
||||
cached_radio_tracks = pickle.loads(
|
||||
cache.get(f"radiosessiontracks{self.session.id}")
|
||||
)
|
||||
logger.info("Using redis cache for radio generation")
|
||||
radio_tracks = cached_radio_tracks
|
||||
if len(radio_tracks) < quantity:
|
||||
|
@ -280,7 +284,9 @@ class CustomMultiple(SessionRadio):
|
|||
|
||||
def validate_session(self, data, **context):
|
||||
data = super().validate_session(data, **context)
|
||||
if data.get("config") is None:
|
||||
try:
|
||||
data["config"] is not None
|
||||
except KeyError:
|
||||
raise serializers.ValidationError(
|
||||
"You must provide a configuration for this radio"
|
||||
)
|
||||
|
|
|
@ -208,7 +208,9 @@ class RadioSessionTracksViewSet(mixins.CreateModelMixin, viewsets.GenericViewSet
|
|||
)
|
||||
# self.perform_create(serializer)
|
||||
# dirty override here, since we use a different serializer for creation and detail
|
||||
evaluated_radio_tracks = pickle.loads(cache.get(f"radiosessiontracks{session.id}"))
|
||||
evaluated_radio_tracks = pickle.loads(
|
||||
cache.get(f"radiosessiontracks{session.id}")
|
||||
)
|
||||
batch = evaluated_radio_tracks[:count]
|
||||
serializer = self.serializer_class(
|
||||
data=batch,
|
||||
|
@ -225,7 +227,9 @@ class RadioSessionTracksViewSet(mixins.CreateModelMixin, viewsets.GenericViewSet
|
|||
|
||||
# delete the tracks we sent from the cache
|
||||
new_cached_radiotracks = evaluated_radio_tracks[count:]
|
||||
cache.set(f"radiosessiontracks{session.id}", pickle.dumps(new_cached_radiotracks))
|
||||
cache.set(
|
||||
f"radiosessiontracks{session.id}", pickle.dumps(new_cached_radiotracks)
|
||||
)
|
||||
|
||||
return Response(
|
||||
serializer.data, status=status.HTTP_201_CREATED, headers=headers
|
||||
|
|
Loading…
Reference in New Issue