Skip to content

Commit e1cadcb

Browse files
committed
Added caching to avoid calling the meat of each of the Session minutes(), recordings(), bluesheets(), slides(), drafts() methods more than once per session. This removes another 3*#sessions sql queries when the materials are all in place (less when the first invocation reurns nothing).
- Legacy-Id: 12219
1 parent af584c6 commit e1cadcb

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

ietf/meeting/models.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,8 +1004,9 @@ def get_material(self, material_type, only_one):
10041004
for d in l:
10051005
d.meeting_related = lambda: True
10061006
else:
1007-
l = self.materials.filter(type=material_type).exclude(states__type=material_type, states__slug='deleted').order_by('sessionpresentation__order')
1008-
1007+
if not hasattr(self, '_cached_materials'):
1008+
self._cached_materials = self.materials.exclude(states__slug='deleted').order_by('sessionpresentation__order')
1009+
l = self._cached_materials.filter(type=material_type).exclude(states__type=material_type)
10091010
if only_one:
10101011
if l:
10111012
return l[0]
@@ -1020,21 +1021,29 @@ def agenda(self):
10201021
return self._agenda_cache
10211022

10221023
def minutes(self):
1023-
return self.get_material("minutes", only_one=True)
1024+
if not hasattr(self, "_minutes_cache"):
1025+
self._minutes_cache = self.get_material("minutes", only_one=True)
1026+
return self._minutes_cache
10241027

10251028
def recordings(self):
1026-
return list(self.get_material("recording", only_one=False))
1029+
if not hasattr(self, "_recordings_cache"):
1030+
self._recordings_cache = list(self.get_material("recording", only_one=False))
1031+
return self._recordings_cache
10271032

10281033
def bluesheets(self):
1029-
return list(self.get_material("bluesheets", only_one=False))
1034+
if not hasattr(self, "_bluesheets_cache"):
1035+
self._bluesheets_cache = list(self.get_material("bluesheets", only_one=False))
1036+
return self._bluesheets_cache
10301037

10311038
def slides(self):
10321039
if not hasattr(self, "_slides_cache"):
10331040
self._slides_cache = list(self.get_material("slides", only_one=False))
10341041
return self._slides_cache
10351042

10361043
def drafts(self):
1037-
return list(self.materials.filter(type='draft'))
1044+
if not hasattr(self, "_drafts_cache"):
1045+
self._drafts_cache = list(self.materials.filter(type='draft'))
1046+
return self._drafts_cache
10381047

10391048
def all_meeting_sessions_for_group(self):
10401049
#sessions = [s for s in self.meeting.session_set.filter(group=self.group,type=self.type) if s.official_timeslotassignment()]

0 commit comments

Comments
 (0)