Browse Source

Optimize db query in `sendalerts`

pull/211/head
Pēteris Caune 6 years ago
parent
commit
11f65ff7aa
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
1 changed files with 6 additions and 1 deletions
  1. +6
    -1
      hc/api/management/commands/sendalerts.py

+ 6
- 1
hc/api/management/commands/sendalerts.py View File

@ -82,7 +82,12 @@ class Command(BaseCommand):
now = timezone.now() now = timezone.now()
check = Check.objects.filter(alert_after__lt=now, status="up").first()
# In PostgreSQL, add this index to run the below query efficiently:
# CREATE INDEX api_check_up ON api_check (alert_after) WHERE status = 'up'
q = Check.objects.filter(alert_after__lt=now, status="up")
# Sort by alert_after, to avoid unnecessary sorting by id:
check = q.order_by("alert_after").first()
if check is None: if check is None:
return False return False


Loading…
Cancel
Save