Skip to content
Snippets Groups Projects
Commit 8896ba68 authored by Benjamin Hättasch's avatar Benjamin Hättasch
Browse files

Speedup views of AKPlan

Make sure event is only loaded once
Massively reduce amount of SQL queries (e.g., plan view reduced from multiple queries per AK where over half of them are duplicates down to only 2 queries -- independent of AK count)
Replace software-side list constructions with in-database operations
parent 26cc3f0f
Branches
No related tags found
No related merge requests found
...@@ -25,7 +25,8 @@ class EventSlugMixin: ...@@ -25,7 +25,8 @@ class EventSlugMixin:
def _load_event(self): def _load_event(self):
# Find event based on event slug # Find event based on event slug
self.event = get_object_or_404(Event, slug=self.kwargs.get("event_slug", None)) if self.event is None:
self.event = get_object_or_404(Event, slug=self.kwargs.get("event_slug", None))
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
self._load_event() self._load_event()
......
...@@ -81,7 +81,7 @@ ...@@ -81,7 +81,7 @@
{% block content %} {% block content %}
<div class="float-right"> <div class="float-right">
<ul class="nav nav-pills"> <ul class="nav nav-pills">
{% if event.room_set.count > 0 %} {% if rooms|length > 0 %}
<li class="nav-item dropdown"> <li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" <a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button"
aria-haspopup="true" aria-haspopup="true"
...@@ -94,13 +94,13 @@ ...@@ -94,13 +94,13 @@
</div> </div>
</li> </li>
{% endif %} {% endif %}
{% if event.aktrack_set.count > 0 %} {% if tracks|length > 0 %}
<li class="nav-item dropdown"> <li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" <a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button"
aria-haspopup="true" aria-haspopup="true"
aria-expanded="false">{% trans "Tracks" %}</a> aria-expanded="false">{% trans "Tracks" %}</a>
<div class="dropdown-menu"> <div class="dropdown-menu">
{% for t in event.aktrack_set.all %} {% for t in tracks %}
<a class="dropdown-item" <a class="dropdown-item"
href="{% url "plan:plan_track" event_slug=event.slug pk=t.pk %}">{{ t }}</a> href="{% url "plan:plan_track" event_slug=event.slug pk=t.pk %}">{{ t }}</a>
{% endfor %} {% endfor %}
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
{% block encode %} {% block encode %}
[ [
{% for slot in room.akslot_set.all %} {% for slot in slots %}
{% if slot.start %} {% if slot.start %}
{'title': '{{ slot.ak }}', {'title': '{{ slot.ak }}',
'start': '{{ slot.start | timezone:event.timezone | date:"Y-m-d H:i:s" }}', 'start': '{{ slot.start | timezone:event.timezone | date:"Y-m-d H:i:s" }}',
......
...@@ -18,7 +18,7 @@ class PlanIndexView(FilterByEventSlugMixin, ListView): ...@@ -18,7 +18,7 @@ class PlanIndexView(FilterByEventSlugMixin, ListView):
def get_queryset(self): def get_queryset(self):
# Ignore slots not scheduled yet # Ignore slots not scheduled yet
return super().get_queryset().filter(start__isnull=False) return super().get_queryset().filter(start__isnull=False).select_related('ak', 'room', 'ak__category')
def get_context_data(self, *, object_list=None, **kwargs): def get_context_data(self, *, object_list=None, **kwargs):
context = super().get_context_data(object_list=object_list, **kwargs) context = super().get_context_data(object_list=object_list, **kwargs)
...@@ -54,6 +54,8 @@ class PlanIndexView(FilterByEventSlugMixin, ListView): ...@@ -54,6 +54,8 @@ class PlanIndexView(FilterByEventSlugMixin, ListView):
if settings.PLAN_SHOW_HIERARCHY: if settings.PLAN_SHOW_HIERARCHY:
context["buildings"] = sorted(buildings) context["buildings"] = sorted(buildings)
context["tracks"] = self.event.aktrack_set.all()
return context return context
...@@ -94,6 +96,11 @@ class PlanRoomView(FilterByEventSlugMixin, DetailView): ...@@ -94,6 +96,11 @@ class PlanRoomView(FilterByEventSlugMixin, DetailView):
model = Room model = Room
context_object_name = "room" context_object_name = "room"
def get_context_data(self, *, object_list=None, **kwargs):
context = super().get_context_data(object_list=object_list, **kwargs)
context["slots"] = AKSlot.objects.filter(room=context['room']).select_related('ak', 'ak__category', 'ak__track')
return context
class PlanTrackView(FilterByEventSlugMixin, DetailView): class PlanTrackView(FilterByEventSlugMixin, DetailView):
template_name = "AKPlan/plan_track.html" template_name = "AKPlan/plan_track.html"
...@@ -102,9 +109,5 @@ class PlanTrackView(FilterByEventSlugMixin, DetailView): ...@@ -102,9 +109,5 @@ class PlanTrackView(FilterByEventSlugMixin, DetailView):
def get_context_data(self, *, object_list=None, **kwargs): def get_context_data(self, *, object_list=None, **kwargs):
context = super().get_context_data(object_list=object_list, **kwargs) context = super().get_context_data(object_list=object_list, **kwargs)
context["slots"] = AKSlot.objects.filter(event=self.event, ak__track=context['track']).select_related('ak', 'room', 'ak__category')
context["slots"] = []
for ak in context["track"].ak_set.all():
context["slots"].extend(ak.akslot_set.all())
return context return context
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment