From 1392226538f3a51b1a54b2d775ee9e7fa0caa40b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Wed, 17 Jan 2018 00:49:03 +0200 Subject: [PATCH] sendalerts was not using the api_check (status, user_id, alert_after) index so removing it. The index was not selective enough. --- hc/api/management/commands/sendalerts.py | 2 +- hc/api/migrations/0036_auto_20180116_2243.py | 19 +++++++++++++++++++ hc/api/models.py | 5 ----- 3 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 hc/api/migrations/0036_auto_20180116_2243.py diff --git a/hc/api/management/commands/sendalerts.py b/hc/api/management/commands/sendalerts.py index a1a25104..5da666d4 100644 --- a/hc/api/management/commands/sendalerts.py +++ b/hc/api/management/commands/sendalerts.py @@ -28,7 +28,7 @@ def notify_on_thread(check_id, stdout): class Command(BaseCommand): help = 'Sends UP/DOWN email alerts' - owned = Check.objects.filter(user__isnull=False) + owned = Check.objects.filter(user__isnull=False).order_by("alert_after") def add_arguments(self, parser): parser.add_argument( diff --git a/hc/api/migrations/0036_auto_20180116_2243.py b/hc/api/migrations/0036_auto_20180116_2243.py new file mode 100644 index 00000000..df4d7748 --- /dev/null +++ b/hc/api/migrations/0036_auto_20180116_2243.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.6 on 2018-01-16 22:43 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0035_auto_20171229_2008'), + ] + + operations = [ + migrations.AlterIndexTogether( + name='check', + index_together=set([]), + ), + ] diff --git a/hc/api/models.py b/hc/api/models.py index 73bd564a..3bafa42e 100644 --- a/hc/api/models.py +++ b/hc/api/models.py @@ -57,11 +57,6 @@ def isostring(dt): class Check(models.Model): - - class Meta: - # sendalerts command will query using these - index_together = ["status", "user", "alert_after"] - name = models.CharField(max_length=100, blank=True) tags = models.CharField(max_length=500, blank=True) code = models.UUIDField(default=uuid.uuid4, editable=False, db_index=True)