Commit fd68689e authored by fred's avatar fred
Browse files

rework main_sound prefetching

parent c61a52a0
...@@ -49,14 +49,18 @@ class EmissionMixin: ...@@ -49,14 +49,18 @@ class EmissionMixin:
# get all related soundfiles in a single query # get all related soundfiles in a single query
soundfiles = {} soundfiles = {}
if episode_ids is not None:
for episode_id in episode_ids:
soundfiles[episode_id] = None
else:
for episode in Episode.objects.filter(emission=emission):
soundfiles[episode.id] = None
for soundfile in SoundFile.objects.select_related().filter(podcastable=True, for soundfile in SoundFile.objects.select_related().filter(podcastable=True,
fragment=False, episode__emission=emission): fragment=False, episode__emission=emission):
soundfiles[soundfile.episode_id] = soundfile soundfiles[soundfile.episode_id] = soundfile
# replace dynamic property by a static attribute, to avoid database Episode.set_prefetched_soundfiles(soundfiles)
# lookups
for episode in context['episodes']:
episode.main_sound = soundfiles.get(episode.id)
#context['futurEpisodes'] = context['episodes'].filter(first_diffusion='2013')[0:3] #context['futurEpisodes'] = context['episodes'].filter(first_diffusion='2013')[0:3]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment