Browse Source

sendreports, sendalerts: and avoid db access while rendering templates--template renderer swallows any exceptions

sendreports: use select_related() to avoid doing N queries
py2
Pēteris Caune 7 years ago
parent
commit
b191b968f3
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
2 changed files with 11 additions and 2 deletions
  1. +4
    -0
      hc/accounts/models.py
  2. +7
    -2
      hc/api/transports.py

+ 4
- 0
hc/accounts/models.py View File

@ -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,


+ 7
- 2
hc/api/transports.py View File

@ -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)


Loading…
Cancel
Save