From af584c6a1f30d8aea4e47dc8bb3d3353c402f566 Mon Sep 17 00:00:00 2001 From: Henrik Levkowetz Date: Wed, 26 Oct 2016 19:06:06 +0000 Subject: [PATCH] Removed caching of the materials page (edit buttons are different for different users), and used select_related() and code re-write to reduce the sql query count from ~1900 to ~600, query time from ~2s to ~0.5s. More can be done, but the page response time is more acceptable now. - Legacy-Id: 12218 --- ietf/meeting/models.py | 7 +- ietf/meeting/views.py | 15 +- .../meeting/edit_materials_button.html | 4 +- ietf/templates/meeting/materials.html | 231 +++++++++--------- 4 files changed, 131 insertions(+), 126 deletions(-) diff --git a/ietf/meeting/models.py b/ietf/meeting/models.py index 0552c4eff..98fd004d2 100644 --- a/ietf/meeting/models.py +++ b/ietf/meeting/models.py @@ -1037,8 +1037,11 @@ class Session(models.Model): return list(self.materials.filter(type='draft')) def all_meeting_sessions_for_group(self): - sessions = [s for s in self.meeting.session_set.filter(group=self.group,type=self.type) if s.official_timeslotassignment()] - return sorted(sessions, key = lambda x: x.official_timeslotassignment().timeslot.time) + #sessions = [s for s in self.meeting.session_set.filter(group=self.group,type=self.type) if s.official_timeslotassignment()] + #sessions = sorted(sessions, key = lambda x: x.official_timeslotassignment().timeslot.time) + assignments = self.timeslotassignments.filter(schedule=self.meeting.agenda).order_by('timeslot__time') + sessions = [ a.session for a in assignments ] + return sessions def all_meeting_recordings(self): recordings = [] diff --git a/ietf/meeting/views.py b/ietf/meeting/views.py index 6bd046ded..75d373bd5 100644 --- a/ietf/meeting/views.py +++ b/ietf/meeting/views.py @@ -105,23 +105,30 @@ def materials(request, num=None): 'cor_cut_off_date': cor_cut_off_date }) + past_cutoff_date = datetime.date.today() > meeting.get_submission_correction_date() + #sessions = Session.objects.filter(meeting__number=meeting.number, timeslot__isnull=False) schedule = get_schedule(meeting, None) - sessions = Session.objects.filter(meeting__number=meeting.number, timeslotassignments__schedule=schedule).select_related() + sessions = Session.objects.filter(meeting__number=meeting.number, + timeslotassignments__schedule=schedule).select_related('meeting__agenda','status','group__state','group__parent') + for session in sessions: + session.past_cutoff_date = past_cutoff_date plenaries = sessions.filter(name__icontains='plenary') ietf = sessions.filter(group__parent__type__slug = 'area').exclude(group__acronym='edu') irtf = sessions.filter(group__parent__acronym = 'irtf') training = sessions.filter(group__acronym__in=['edu','iaoc'], type_id__in=['session', 'other', ]) iab = sessions.filter(group__parent__acronym = 'iab') - cache_version = Document.objects.filter(session__meeting__number=meeting.number).aggregate(Max('time'))["time__max"] return render(request, "meeting/materials.html", { 'meeting_num': meeting.number, - 'plenaries': plenaries, 'ietf': ietf, 'training': training, 'irtf': irtf, 'iab': iab, + 'plenaries': plenaries, + 'ietf': ietf, + 'training': training, + 'irtf': irtf, + 'iab': iab, 'cut_off_date': cut_off_date, 'cor_cut_off_date': cor_cut_off_date, 'submission_started': now > begin_date, - 'cache_version': cache_version, }) def current_materials(request): diff --git a/ietf/templates/meeting/edit_materials_button.html b/ietf/templates/meeting/edit_materials_button.html index f65338b7b..a27fa6fc6 100644 --- a/ietf/templates/meeting/edit_materials_button.html +++ b/ietf/templates/meeting/edit_materials_button.html @@ -1,6 +1,6 @@ {% load ietf_filters session_filters %} -{% if user|has_role:"Secretariat" or session|can_manage_materials:user and not session.is_material_submission_cutoff %} +{% if user|has_role:"Secretariat" or session|can_manage_materials:user and not session.past_cutoff_date %} {% with gt=session.group.type_id %} -Edit + Edit {% endwith %} {% endif %} diff --git a/ietf/templates/meeting/materials.html b/ietf/templates/meeting/materials.html index c00f6b24b..ceaa6d812 100644 --- a/ietf/templates/meeting/materials.html +++ b/ietf/templates/meeting/materials.html @@ -33,133 +33,128 @@ Meeting requests/conflicts

- {# cache for 15 minutes, as long as there's no proceedings activity. takes 4-8 seconds to generate. #} - {% load cache %} - {% cache 900 ietf_meeting_materials meeting_num cache_version %} + {% with "True" as show_agenda %} + + {% if plenaries %} +

Plenaries

+ + + + + + + + + + - {% with "True" as show_agenda %} - - {% if plenaries %} -

Plenaries

-
GroupAgendaMinutesSlidesDrafts
- - - - - - - - - + + {% for session in plenaries %} + {% include "meeting/group_materials.html" %} + {% endfor %} + +
GroupAgendaMinutesSlidesDrafts
+ {% endif %} - - {% for session in plenaries %} - {% include "meeting/group_materials.html" %} - {% endfor %} - - - {% endif %} + + {% regroup ietf|dictsort:"group.parent.acronym" by group.parent.name as areas %} + {% for sessions in areas %} +

{{sessions.list.0.group.parent.acronym|upper}} {{ sessions.grouper }}

+ + + + + + + + + + - - {% regroup ietf|dictsort:"group.parent.acronym" by group.parent.name as areas %} - {% for sessions in areas %} -

{{sessions.list.0.group.parent.acronym|upper}} {{ sessions.grouper }}

-
GroupAgendaMinutesSlidesDrafts
- - - - - - - - - + + {% for session in sessions.list|dictsort:"group.acronym" %} + {% ifchanged session.group.acronym %} + {% include "meeting/group_materials.html" %} + {% endifchanged %} + {% endfor %} + +
GroupAgendaMinutesSlidesDrafts
+ {% endfor %} - - {% for session in sessions.list|dictsort:"group.acronym" %} - {% ifchanged session.group.acronym %} - {% include "meeting/group_materials.html" %} - {% endifchanged %} - {% endfor %} - - - {% endfor %} + + {% if training %} + {% with "False" as show_agenda %} +

Training

+ + + + + + + + + + - - {% if training %} - {% with "False" as show_agenda %} -

Training

-
GroupAgendaMinutesSlidesDrafts
- - - - - - - - - + + {% for session in training %} + {% ifchanged %} + {% include "meeting/group_materials.html" %} + {% endifchanged %} + {% endfor %} + +
GroupAgendaMinutesSlidesDrafts
+ {% endwith %} + {% endif %} - - {% for session in training %} - {% ifchanged %} - {% include "meeting/group_materials.html" %} - {% endifchanged %} - {% endfor %} - - - {% endwith %} - {% endif %} + + {% if iab %} +

IAB Internet Architecture Board

+ + + + + + + + + + - - {% if iab %} -

IAB Internet Architecture Board

-
GroupAgendaMinutesSlidesDrafts
- - - - - - - - - + + {% for session in iab %} + {% ifchanged %} + {% include "meeting/group_materials.html" %} + {% endifchanged %} + {% endfor %} + +
GroupAgendaMinutesSlidesDrafts
+ {% endif %} - - {% for session in iab %} - {% ifchanged %} - {% include "meeting/group_materials.html" %} - {% endifchanged %} - {% endfor %} - - - {% endif %} + + {% if irtf %} +

IRTF Internet Research Task Force

+ + + + + + + + + + - - {% if irtf %} -

IRTF Internet Research Task Force

-
GroupAgendaMinutesSlidesDrafts
- - - - - - - - - - - - {% for session in irtf|dictsort:"group.acronym" %} - {% ifchanged %} - {% include "meeting/group_materials.html" %} - {% endifchanged %} - {% endfor %} - -
GroupAgendaMinutesSlidesDrafts
- {% endif %} - {% endwith %} - {% endcache %} + + {% for session in irtf|dictsort:"group.acronym" %} + {% ifchanged %} + {% include "meeting/group_materials.html" %} + {% endifchanged %} + {% endfor %} + + + {% endif %} + {% endwith %}