forked from GithubBackups/healthchecks
sendreports, sendalerts: and avoid db access while rendering templates--template renderer swallows any exceptions
sendreports: use select_related() to avoid doing N queries
This commit is contained in:
parent
9703f411f7
commit
b191b968f3
@ -144,7 +144,11 @@ class Profile(models.Model):
|
|||||||
|
|
||||||
# Sort checks by owner. Need this because will group by owner in
|
# Sort checks by owner. Need this because will group by owner in
|
||||||
# template.
|
# template.
|
||||||
|
checks = checks.select_related("user", "user__profile")
|
||||||
checks = checks.order_by("user_id")
|
checks = checks.order_by("user_id")
|
||||||
|
# list() executes the query, to avoid DB access while
|
||||||
|
# rendering the template
|
||||||
|
checks = list(checks)
|
||||||
|
|
||||||
ctx = {
|
ctx = {
|
||||||
"checks": checks,
|
"checks": checks,
|
||||||
|
@ -60,9 +60,11 @@ class Email(Transport):
|
|||||||
# Default sort order is by check's creation time
|
# Default sort order is by check's creation time
|
||||||
sort = "created"
|
sort = "created"
|
||||||
|
|
||||||
|
# list() executes the query, to avoid DB access while
|
||||||
|
# rendering a template
|
||||||
ctx = {
|
ctx = {
|
||||||
"check": check,
|
"check": check,
|
||||||
"checks": self.checks(),
|
"checks": list(self.checks()),
|
||||||
"sort": sort,
|
"sort": sort,
|
||||||
"now": timezone.now(),
|
"now": timezone.now(),
|
||||||
"unsub_link": self.channel.get_unsub_link()
|
"unsub_link": self.channel.get_unsub_link()
|
||||||
@ -288,9 +290,12 @@ class Pushover(HttpTransport):
|
|||||||
|
|
||||||
def notify(self, check):
|
def notify(self, check):
|
||||||
others = self.checks().filter(status="down").exclude(code=check.code)
|
others = self.checks().filter(status="down").exclude(code=check.code)
|
||||||
|
|
||||||
|
# list() executes the query, to avoid DB access while
|
||||||
|
# rendering a template
|
||||||
ctx = {
|
ctx = {
|
||||||
"check": check,
|
"check": check,
|
||||||
"down_checks": others,
|
"down_checks": list(others),
|
||||||
}
|
}
|
||||||
text = tmpl("pushover_message.html", **ctx)
|
text = tmpl("pushover_message.html", **ctx)
|
||||||
title = tmpl("pushover_title.html", **ctx)
|
title = tmpl("pushover_title.html", **ctx)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user