Commit a80082cc authored by Simon Daron's avatar Simon Daron

Recent listen on home @fred request perf check

parent 59586851
...@@ -384,6 +384,28 @@ class Home(TemplateView): ...@@ -384,6 +384,28 @@ class Home(TemplateView):
days.append({'schedules': [x for x in schedules if x.is_on_weekday(day+1)], days.append({'schedules': [x for x in schedules if x.is_on_weekday(day+1)],
'datetime': datetime(2007, 1, day+1)}) 'datetime': datetime(2007, 1, day+1)})
context['days'] = days context['days'] = days
context['episodes'] = Episode.objects.filter(
soundfile__podcastable=True, soundfile__fragment=False) \
.select_related().extra(select={
'first_diffusion': 'emissions_diffusion.datetime', },
select_params=(False, True),
where=['''datetime = (SELECT MIN(datetime)
FROM emissions_diffusion
WHERE episode_id = emissions_episode.id)'''],
tables=['emissions_diffusion'],).order_by('-first_diffusion') [:6]
# get all related soundfiles in a single query
soundfiles = {}
for soundfile in SoundFile.objects.select_related().filter(podcastable=True,
fragment=False, episode__in=[x.id for x in context['episodes']]):
soundfiles[soundfile.episode_id] = soundfile
# replace dynamic property by a static attribute, to avoid database
# lookups
for episode in context['episodes']:
episode.main_sound = soundfiles.get(episode.id)
return context return context
home = Home.as_view() home = Home.as_view()
......
...@@ -12,6 +12,14 @@ ...@@ -12,6 +12,14 @@
<div class="wrapper"> <div class="wrapper">
<h2>Cette semaine sur Panik</h2> <h2>Cette semaine sur Panik</h2>
{% weekview %} {% weekview %}
<h2>Ecouter</h2>
<ul class="custom columns list">
{% for episode in episodes %}
<li class="item {% if episode.emission.categories.all.count = 0 %}nocat{% endif %} {% for category in episode.emission.categories.all %} {{ category|slugify }}{% endfor %}">
{% episode_resume model="inline" klass="standalone"%}
</li>
{% endfor %}
</ul>
</div> </div>
</div> </div>
{% endblock %} {% endblock %}
......
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