Merged in [18103] from olau@iola.dk:

Prefetch a couple of things in the agenda view to reduce the number of
queries for IETF 106 from about 3800 to about 235.
 - Legacy-Id: 18452
Note: SVN reference [18103] has been migrated to Git commit a373f1d55c
This commit is contained in:
Henrik Levkowetz 2020-08-31 20:09:03 +00:00
commit e9bebe1274
4 changed files with 22 additions and 17 deletions

View file

@ -9,7 +9,7 @@ import re
from tempfile import mkstemp
from django.http import HttpRequest, Http404
from django.db.models import Max, Q, Prefetch
from django.db.models import F, Max, Q, Prefetch
from django.conf import settings
from django.core.cache import cache
from django.urls import reverse
@ -171,13 +171,17 @@ def get_schedule_by_name(meeting, owner, name):
return meeting.schedule_set.filter(name = name).first()
def preprocess_assignments_for_agenda(assignments_queryset, meeting, extra_prefetches=()):
assignments_queryset = assignments_queryset.select_related(
"timeslot", "timeslot__location", "timeslot__type",
).prefetch_related(
assignments_queryset = assignments_queryset.prefetch_related(
'timeslot', 'timeslot__type', 'timeslot__meeting',
'timeslot__location', 'timeslot__location__floorplan', 'timeslot__location__urlresource_set',
Prefetch(
"session",
queryset=add_event_info_to_session_qs(Session.objects.all().prefetch_related(
'group', 'group__charter', 'group__charter__group',
Prefetch('materials',
queryset=Document.objects.exclude(states__type=F("type"), states__slug='deleted').order_by('sessionpresentation__order').prefetch_related('states'),
to_attr='prefetched_active_materials'
)
))
),
*extra_prefetches
@ -222,6 +226,12 @@ def preprocess_assignments_for_agenda(assignments_queryset, meeting, extra_prefe
if a.session and a.session.historic_group and a.session.historic_group.parent_id:
a.session.historic_group.historic_parent = parent_replacements.get(a.session.historic_group.parent_id)
for d in a.session.prefetched_active_materials:
# make sure these are precomputed with the meeting instead
# of having to look it up
d.get_href(meeting=meeting)
d.get_versionless_href(meeting=meeting)
return assignments
def read_session_file(type, num, doc):

View file

@ -398,14 +398,14 @@ class Room(models.Model):
return self.functional_name
# audio stream support
def audio_stream_url(self):
urlresource = self.urlresource_set.filter(name_id='audiostream').first()
return urlresource.url if urlresource else None
urlresources = [ur for ur in self.urlresource_set.all() if ur.name_id == 'audiostream']
return urlresources[0].url if urlresources else None
def video_stream_url(self):
urlresource = self.urlresource_set.filter(name_id__in=['meetecho', ]).first()
return urlresource.url if urlresource else None
urlresources = [ur for ur in self.urlresource_set.all() if ur.name_id in ['meetecho']]
return urlresources[0].url if urlresources else None
def webex_url(self):
urlresource = self.urlresource_set.filter(name_id__in=['webex', ]).first()
return urlresource.url if urlresource else None
urlresources = [ur for ur in self.urlresource_set.all() if ur.name_id in ['webex']]
return urlresources[0].url if urlresources else None
#
class Meta:
ordering = ["-id"]

View file

@ -32,7 +32,7 @@ from django.contrib.auth.decorators import login_required
from django.core.exceptions import ValidationError
from django.core.validators import URLValidator
from django.urls import reverse,reverse_lazy
from django.db.models import F, Min, Max, Prefetch, Q
from django.db.models import F, Min, Max, Q
from django.forms.models import modelform_factory, inlineformset_factory
from django.template import TemplateDoesNotExist
from django.template.loader import render_to_string
@ -1319,11 +1319,6 @@ def agenda_json(request, num=None ):
# Update the assignments with historic information, i.e., valid at the
# time of the meeting
assignments = preprocess_assignments_for_agenda(assignments, meeting, extra_prefetches=[
# sadly, these prefetches aren't enough to get rid of all implicit queries below
Prefetch("session__materials",
queryset=Document.objects.exclude(states__type=F("type"),states__slug='deleted').select_related("group").order_by("sessionpresentation__order"),
to_attr="prefetched_active_materials",
),
"session__materials__docevent_set",
"session__sessionpresentation_set",
"timeslot__meeting"

View file

@ -1,4 +1,4 @@
<div id="session{{ session.pk }}" class="session {% if not session.group.parent.scheduling_color %}untoggleable{% endif %} {% if session.parent_acronym %}parent-{{ session.parent_acronym }}{% endif %}" style="width:{{ session.layout_width }}em;" data-duration="{{ session.requested_duration.total_seconds }}" {% if session.attendees != None %}data-attendees="{{ session.attendees }}"{% endif %}>
<div id="session{{ session.pk }}" class="session {% if not session.group.parent.scheduling_color %}untoggleable{% endif %} {% if session.parent_acronym %}parent-{{ session.parent_acronym }}{% endif %} {% if session.is_tombstone %}tombstone{% endif %}" style="width:{{ session.layout_width }}em;" data-duration="{{ session.requested_duration.total_seconds }}" {% if session.attendees != None %}data-attendees="{{ session.attendees }}"{% endif %}>
<div class="session-label {% if session.group and session.group.is_bof %}bof-session{% endif %}">
{{ session.scheduling_label }}
</div>