diff --git a/hc/accounts/models.py b/hc/accounts/models.py index d1f22729..f4db9225 100644 --- a/hc/accounts/models.py +++ b/hc/accounts/models.py @@ -144,7 +144,11 @@ class Profile(models.Model): # Sort checks by owner. Need this because will group by owner in # template. + checks = checks.select_related("user", "user__profile") checks = checks.order_by("user_id") + # list() executes the query, to avoid DB access while + # rendering the template + checks = list(checks) ctx = { "checks": checks, diff --git a/hc/api/transports.py b/hc/api/transports.py index 69cba040..23d2248e 100644 --- a/hc/api/transports.py +++ b/hc/api/transports.py @@ -60,9 +60,11 @@ class Email(Transport): # Default sort order is by check's creation time sort = "created" + # list() executes the query, to avoid DB access while + # rendering a template ctx = { "check": check, - "checks": self.checks(), + "checks": list(self.checks()), "sort": sort, "now": timezone.now(), "unsub_link": self.channel.get_unsub_link() @@ -288,9 +290,12 @@ class Pushover(HttpTransport): def notify(self, check): others = self.checks().filter(status="down").exclude(code=check.code) + + # list() executes the query, to avoid DB access while + # rendering a template ctx = { "check": check, - "down_checks": others, + "down_checks": list(others), } text = tmpl("pushover_message.html", **ctx) title = tmpl("pushover_title.html", **ctx)