confirmation: Add an index on content_type, object_id.

This makes lookups of `.confirmation`, or joins through
`confirmation__` as we do in the `/json/invites`, actually fast.  See
https://code.djangoproject.com/ticket/23435
This commit is contained in:
Alex Vandiver 2024-07-10 17:21:36 +00:00 committed by Tim Abbott
parent ab1e858eb9
commit fcb04598f0
2 changed files with 24 additions and 0 deletions

View File

@ -0,0 +1,21 @@
from django.contrib.postgres.operations import AddIndexConcurrently
from django.db import migrations, models
class Migration(migrations.Migration):
atomic = False
dependencies = [
("confirmation", "0013_alter_realmcreationkey_id"),
("contenttypes", "0002_remove_content_type_name"),
("zerver", "0552_remove_realm_private_message_policy"),
]
operations = [
AddIndexConcurrently(
model_name="confirmation",
index=models.Index(
fields=["content_type", "object_id"], name="confirmatio_content_80155a_idx"
),
),
]

View File

@ -231,6 +231,9 @@ class Confirmation(models.Model):
class Meta:
unique_together = ("type", "confirmation_key")
indexes = [
models.Index(fields=["content_type", "object_id"]),
]
@override
def __str__(self) -> str: