From b37d908879e80b81616c3e9a9f92d968d5c327de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Sat, 20 Jul 2019 12:17:00 +0300 Subject: [PATCH] Optimization: don't instantiate Flip objects in Check.downtimes() --- hc/api/models.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/hc/api/models.py b/hc/api/models.py index d3f648b6..d7e11e39 100644 --- a/hc/api/models.py +++ b/hc/api/models.py @@ -265,8 +265,9 @@ class Check(models.Model): # A list of flips and month boundaries events = [(b, "---") for b in boundaries] - for flip in self.flip_set.filter(created__gt=min(boundaries)): - events.append((flip.created, flip.old_status)) + q = self.flip_set.filter(created__gt=min(boundaries)) + for pair in q.values_list("created", "old_status"): + events.append(pair) # Iterate through flips and month boundaries in reverse order, # and for each "down" event increase the counters in `totals`.