Skip to content

Commit b9e5c9b

Browse files
committed
Fix problem with assignments to the same session causing a crash.
Commit ready for merge - Legacy-Id: 17181
1 parent 49fc0d7 commit b9e5c9b

2 files changed

Lines changed: 22 additions & 31 deletions

File tree

ietf/meeting/helpers.py

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright The IETF Trust 2013-2019, All Rights Reserved
1+
# Copyright The IETF Trust 2013-2020, All Rights Reserved
22
# -*- coding: utf-8 -*-
33

44

@@ -11,7 +11,7 @@
1111
from tempfile import mkstemp
1212

1313
from django.http import HttpRequest, Http404
14-
from django.db.models import Max, Q
14+
from django.db.models import Max, Q, Prefetch
1515
from django.conf import settings
1616
from django.core.cache import cache
1717
from django.urls import reverse
@@ -27,7 +27,7 @@
2727
from ietf.liaisons.utils import get_person_for_user
2828
from ietf.mailtrigger.utils import gather_address_lists
2929
from ietf.person.models import Person
30-
from ietf.meeting.models import Meeting, Schedule, TimeSlot, SchedTimeSessAssignment, ImportantDate, SchedulingEvent
30+
from ietf.meeting.models import Meeting, Schedule, TimeSlot, SchedTimeSessAssignment, ImportantDate, SchedulingEvent, Session
3131
from ietf.meeting.utils import session_requested_by, add_event_info_to_session_qs
3232
from ietf.name.models import ImportantDateName
3333
from ietf.utils.history import find_history_active_at, find_history_replacements_active_at
@@ -164,23 +164,19 @@ def get_schedule_by_name(meeting, owner, name):
164164
else:
165165
return meeting.schedule_set.filter(name = name).first()
166166

167-
def preprocess_assignments_for_agenda(assignments_queryset, meeting):
168-
# prefetch was not improving performance, except for json_agenda, so
169-
# it was removed. Saved in comment in case others find it useful
170-
# in the future ...
171-
#
172-
#.prefetch_related(
173-
# Prefetch("session__materials",
174-
# queryset=Document.objects.exclude(states__type=F("type"),states__slug='deleted').select_related("group").order_by("sessionpresentation__order"),
175-
# to_attr="prefetched_active_materials",
176-
# ),
177-
# "timeslot__meeting",
178-
# )
167+
def preprocess_assignments_for_agenda(assignments_queryset, meeting, extra_prefetches=()):
179168
assignments_queryset = assignments_queryset.select_related(
180169
"timeslot", "timeslot__location", "timeslot__type",
181-
"session", "session__group", "session__group__charter",
182-
"session__group__charter__group",
183-
)
170+
).prefetch_related(
171+
Prefetch(
172+
"session",
173+
queryset=add_event_info_to_session_qs(Session.objects.all().prefetch_related(
174+
'group', 'group__charter', 'group__charter__group',
175+
))
176+
),
177+
*extra_prefetches
178+
)
179+
184180

185181
# removed list(); it was consuming a very large amount of processor time
186182
# assignments = list(assignments_queryset) # make sure we're set in stone
@@ -217,11 +213,6 @@ def preprocess_assignments_for_agenda(assignments_queryset, meeting):
217213
if a.session and a.session.historic_group and a.session.historic_group.parent_id:
218214
a.session.historic_group.historic_parent = parent_replacements.get(a.session.historic_group.parent_id)
219215

220-
# add current session status
221-
sessions = {a.session_id: a.session for a in assignments if a.session}
222-
for e in SchedulingEvent.objects.filter(session__in=sessions.keys()).order_by('time', 'id').iterator():
223-
sessions[e.session_id].current_status = e.status_id
224-
225216
return assignments
226217

227218
def read_session_file(type, num, doc):

ietf/meeting/views.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright The IETF Trust 2007-2019, All Rights Reserved
1+
# Copyright The IETF Trust 2007-2020, All Rights Reserved
22
# -*- coding: utf-8 -*-
33

44

@@ -968,16 +968,16 @@ def json_agenda(request, num=None ):
968968
assignments = meeting.schedule.assignments.exclude(session__type__in=['lead','offagenda','break','reg'])
969969
# Update the assignments with historic information, i.e., valid at the
970970
# time of the meeting
971-
assignments = assignments.prefetch_related(
971+
assignments = preprocess_assignments_for_agenda(assignments, meeting, extra_prefetches=[
972+
# sadly, these prefetches aren't enough to get rid of all implicit queries below
972973
Prefetch("session__materials",
973974
queryset=Document.objects.exclude(states__type=F("type"),states__slug='deleted').select_related("group").order_by("sessionpresentation__order"),
974975
to_attr="prefetched_active_materials",
975-
),
976-
"session__materials__docevent_set",
977-
"session__sessionpresentation_set",
978-
"timeslot__meeting",
979-
)
980-
assignments = preprocess_assignments_for_agenda(assignments, meeting)
976+
),
977+
"session__materials__docevent_set",
978+
"session__sessionpresentation_set",
979+
"timeslot__meeting"
980+
])
981981
for asgn in assignments:
982982
sessdict = dict()
983983
sessdict['objtype'] = 'session'

0 commit comments

Comments
 (0)