Optimization: don't instantiate Flip objects in Check.downtimes()

This commit is contained in:
Pēteris Caune 2019-07-20 12:17:00 +03:00
parent b2ebce6cf9
commit b37d908879
No known key found for this signature in database
GPG Key ID: E28D7679E9A9EDE2

View File

@ -265,8 +265,9 @@ class Check(models.Model):
# A list of flips and month boundaries # A list of flips and month boundaries
events = [(b, "---") for b in boundaries] events = [(b, "---") for b in boundaries]
for flip in self.flip_set.filter(created__gt=min(boundaries)): q = self.flip_set.filter(created__gt=min(boundaries))
events.append((flip.created, flip.old_status)) for pair in q.values_list("created", "old_status"):
events.append(pair)
# Iterate through flips and month boundaries in reverse order, # Iterate through flips and month boundaries in reverse order,
# and for each "down" event increase the counters in `totals`. # and for each "down" event increase the counters in `totals`.