Skip to content

Commit

Permalink
fix(api): add missing database indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
peterthomassen committed Dec 18, 2024
1 parent f5e093d commit f910d62
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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"
),
),
]
2 changes: 1 addition & 1 deletion api/desecapi/models/captcha.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion api/desecapi/models/domains.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
5 changes: 4 additions & 1 deletion api/desecapi/models/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down

0 comments on commit f910d62

Please sign in to comment.