Skip to content

Commit b63c622

Browse files
committed
Streamline a couple of doc helpers to prevent unnecessary DB lookups,
speeds up IESG discusses page up a fair bit - Legacy-Id: 6421
1 parent b6c4f72 commit b63c622

1 file changed

Lines changed: 12 additions & 14 deletions

File tree

ietf/doc/models.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def get_state(self, state_type=None):
122122

123123
if not hasattr(self, "state_cache") or self.state_cache == None:
124124
self.state_cache = {}
125-
for s in self.states.all().select_related():
125+
for s in self.states.all().select_related("type"):
126126
self.state_cache[s.type_id] = s
127127

128128
return self.state_cache.get(state_type, None)
@@ -149,8 +149,8 @@ def ballot_open(self, ballot_type_slug):
149149

150150
def active_ballot(self):
151151
"""Returns the most recently created ballot if it isn't closed."""
152-
ballot = self.latest_event(BallotDocEvent, type="created_ballot")
153-
if ballot and self.ballot_open(ballot.ballot_type.slug):
152+
ballot = self.latest_event(BallotDocEvent, type__in=("created_ballot", "closed_ballot"))
153+
if ballot and ballot.type == "created_ballot":
154154
return ballot
155155
else:
156156
return None
@@ -616,17 +616,15 @@ def active_ad_positions(self):
616616
active_ads = list(Person.objects.filter(role__name="ad", role__group__state="active"))
617617
res = {}
618618

619-
if self.doc.latest_event(BallotDocEvent, type="created_ballot") == self:
620-
621-
positions = BallotPositionDocEvent.objects.filter(type="changed_ballot_position",ad__in=active_ads, ballot=self).select_related('ad', 'pos').order_by("-time", "-id")
622-
623-
for pos in positions:
624-
if pos.ad not in res:
625-
res[pos.ad] = pos
626-
627-
for ad in active_ads:
628-
if ad not in res:
629-
res[ad] = None
619+
positions = BallotPositionDocEvent.objects.filter(type="changed_ballot_position",ad__in=active_ads, ballot=self).select_related('ad', 'pos').order_by("-time", "-id")
620+
621+
for pos in positions:
622+
if pos.ad not in res:
623+
res[pos.ad] = pos
624+
625+
for ad in active_ads:
626+
if ad not in res:
627+
res[ad] = None
630628
return res
631629

632630
def all_positions(self):

0 commit comments

Comments
 (0)