From f910d62ad22b61fb1712f9c6e2e4794e86241a12 Mon Sep 17 00:00:00 2001 From: Peter Thomassen Date: Tue, 17 Dec 2024 16:33:42 +0100 Subject: [PATCH] fix(api): add missing database indexes --- ...ted_alter_domain_renewal_state_and_more.py | 38 +++++++++++++++++++ api/desecapi/models/captcha.py | 2 +- api/desecapi/models/domains.py | 2 +- api/desecapi/models/users.py | 5 ++- 4 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 api/desecapi/migrations/0044_alter_captcha_created_alter_domain_renewal_state_and_more.py diff --git a/api/desecapi/migrations/0044_alter_captcha_created_alter_domain_renewal_state_and_more.py b/api/desecapi/migrations/0044_alter_captcha_created_alter_domain_renewal_state_and_more.py new file mode 100644 index 000000000..36ce6a6b3 --- /dev/null +++ b/api/desecapi/migrations/0044_alter_captcha_created_alter_domain_renewal_state_and_more.py @@ -0,0 +1,38 @@ +# Generated by Django 5.1.4 on 2024-12-17 15:32 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("desecapi", "0043_authenticatedactivateuserwithoverridetokenaction"), + ] + + operations = [ + migrations.AlterField( + model_name="captcha", + name="created", + field=models.DateTimeField(auto_now_add=True, db_index=True), + ), + migrations.AlterField( + model_name="domain", + name="renewal_state", + field=models.IntegerField( + choices=[(0, "Immortal"), (1, "Fresh"), (2, "Notified"), (3, "Warned")], + db_index=True, + default=0, + ), + ), + migrations.AlterField( + model_name="user", + name="is_active", + field=models.BooleanField(db_index=True, default=True, null=True), + ), + migrations.AddIndex( + model_name="user", + index=models.Index( + fields=["last_login"], name="desecapi_us_last_lo_3b1092_idx" + ), + ), + ] diff --git a/api/desecapi/models/captcha.py b/api/desecapi/models/captcha.py index caef079d3..11713d29b 100644 --- a/api/desecapi/models/captcha.py +++ b/api/desecapi/models/captcha.py @@ -35,7 +35,7 @@ class Kind(models.TextChoices): AUDIO = "audio" id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) - created = models.DateTimeField(auto_now_add=True) + created = models.DateTimeField(auto_now_add=True, db_index=True) content = models.CharField(max_length=24, default="") kind = models.CharField(choices=Kind.choices, default=Kind.IMAGE, max_length=24) diff --git a/api/desecapi/models/domains.py b/api/desecapi/models/domains.py index f12d648eb..cd4f5c488 100644 --- a/api/desecapi/models/domains.py +++ b/api/desecapi/models/domains.py @@ -60,7 +60,7 @@ class RenewalState(models.IntegerChoices): published = models.DateTimeField(null=True, blank=True) minimum_ttl = models.PositiveIntegerField(default=_minimum_ttl_default.__func__) renewal_state = models.IntegerField( - choices=RenewalState.choices, default=RenewalState.IMMORTAL + choices=RenewalState.choices, db_index=True, default=RenewalState.IMMORTAL ) renewal_changed = models.DateTimeField(auto_now_add=True) diff --git a/api/desecapi/models/users.py b/api/desecapi/models/users.py index 6bec20f1d..025d4dac0 100644 --- a/api/desecapi/models/users.py +++ b/api/desecapi/models/users.py @@ -40,7 +40,7 @@ def _limit_domains_default(): unique=True, ) email_verified = models.DateTimeField(null=True, blank=True) - is_active = models.BooleanField(default=True, null=True) + is_active = models.BooleanField(db_index=True, default=True, null=True) is_admin = models.BooleanField(default=False) created = models.DateTimeField(auto_now_add=True) credentials_changed = models.DateTimeField(auto_now_add=True) @@ -56,6 +56,9 @@ def _limit_domains_default(): USERNAME_FIELD = "email" REQUIRED_FIELDS = [] + class Meta: + indexes = [models.Index(fields=["last_login"])] + def get_full_name(self): return self.email