Skip to content

Commit a373f1d

Browse files
committed
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: 18103
1 parent 15de8ef commit a373f1d

3 files changed

Lines changed: 21 additions & 11 deletions

File tree

ietf/meeting/helpers.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from tempfile import mkstemp
1010

1111
from django.http import HttpRequest, Http404
12-
from django.db.models import Max, Q, Prefetch
12+
from django.db.models import F, Max, Q, Prefetch
1313
from django.conf import settings
1414
from django.core.cache import cache
1515
from django.urls import reverse
@@ -164,13 +164,17 @@ def get_schedule_by_name(meeting, owner, name):
164164
return meeting.schedule_set.filter(name = name).first()
165165

166166
def preprocess_assignments_for_agenda(assignments_queryset, meeting, extra_prefetches=()):
167-
assignments_queryset = assignments_queryset.select_related(
168-
"timeslot", "timeslot__location", "timeslot__type",
169-
).prefetch_related(
167+
assignments_queryset = assignments_queryset.prefetch_related(
168+
'timeslot', 'timeslot__type', 'timeslot__meeting',
169+
'timeslot__location', 'timeslot__location__floorplan', 'timeslot__location__urlresource_set',
170170
Prefetch(
171171
"session",
172172
queryset=add_event_info_to_session_qs(Session.objects.all().prefetch_related(
173173
'group', 'group__charter', 'group__charter__group',
174+
Prefetch('materials',
175+
queryset=Document.objects.exclude(states__type=F("type"), states__slug='deleted').order_by('sessionpresentation__order').prefetch_related('states'),
176+
to_attr='prefetched_active_materials'
177+
)
174178
))
175179
),
176180
*extra_prefetches
@@ -212,6 +216,12 @@ def preprocess_assignments_for_agenda(assignments_queryset, meeting, extra_prefe
212216
if a.session and a.session.historic_group and a.session.historic_group.parent_id:
213217
a.session.historic_group.historic_parent = parent_replacements.get(a.session.historic_group.parent_id)
214218

219+
for d in a.session.prefetched_active_materials:
220+
# make sure these are precomputed with the meeting instead
221+
# of having to look it up
222+
d.get_href(meeting=meeting)
223+
d.get_versionless_href(meeting=meeting)
224+
215225
return assignments
216226

217227
def read_session_file(type, num, doc):

ietf/meeting/models.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -391,14 +391,14 @@ def functional_display_name(self):
391391
return self.functional_name
392392
# audio stream support
393393
def audio_stream_url(self):
394-
urlresource = self.urlresource_set.filter(name_id='audiostream').first()
395-
return urlresource.url if urlresource else None
394+
urlresources = [ur for ur in self.urlresource_set.all() if ur.name_id == 'audiostream']
395+
return urlresources[0].url if urlresources else None
396396
def video_stream_url(self):
397-
urlresource = self.urlresource_set.filter(name_id__in=['meetecho', ]).first()
398-
return urlresource.url if urlresource else None
397+
urlresources = [ur for ur in self.urlresource_set.all() if ur.name_id in ['meetecho']]
398+
return urlresources[0].url if urlresources else None
399399
def webex_url(self):
400-
urlresource = self.urlresource_set.filter(name_id__in=['webex', ]).first()
401-
return urlresource.url if urlresource else None
400+
urlresources = [ur for ur in self.urlresource_set.all() if ur.name_id in ['webex']]
401+
return urlresources[0].url if urlresources else None
402402
#
403403
class Meta:
404404
ordering = ["-id"]

ietf/templates/meeting/edit_meeting_schedule_session.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<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 %}>
1+
<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 %}>
22
<div class="session-label {% if session.group and session.group.is_bof %}bof-session{% endif %}">
33
{{ session.scheduling_label }}
44
</div>

0 commit comments

Comments
 (0)