Permalink
Browse files

sendreports, sendalerts: and avoid db access while rendering template…

…s--template renderer swallows any exceptions

sendreports: use select_related() to avoid doing N queries
  • Loading branch information...
cuu508 committed Mar 23, 2018
1 parent 9703f41 commit b191b968f39e6e48143bb6286b58133cd14fa305
Showing with 11 additions and 2 deletions.
  1. +4 −0 hc/accounts/models.py
  2. +7 −2 hc/api/transports.py
@@ -144,7 +144,11 @@ def send_report(self, nag=False):

# 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,
@@ -60,9 +60,11 @@ def notify(self, check, bounce_url):
# 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)

0 comments on commit b191b96

Please sign in to comment.