From e3d1ff1cc215a72dada8037a80fbcfe14de1eefd Mon Sep 17 00:00:00 2001 From: Alex Vandiver Date: Wed, 10 Jul 2024 17:21:36 +0000 Subject: [PATCH] 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 (cherry picked from commit fcb04598f0ea070b00127e8a1839141b865bda2f) --- ...irmation_confirmatio_content_80155a_idx.py | 21 +++++++++++++++++++ confirmation/models.py | 3 +++ 2 files changed, 24 insertions(+) create mode 100644 confirmation/migrations/0014_confirmation_confirmatio_content_80155a_idx.py diff --git a/confirmation/migrations/0014_confirmation_confirmatio_content_80155a_idx.py b/confirmation/migrations/0014_confirmation_confirmatio_content_80155a_idx.py new file mode 100644 index 0000000000..a9e1c94202 --- /dev/null +++ b/confirmation/migrations/0014_confirmation_confirmatio_content_80155a_idx.py @@ -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" + ), + ), + ] diff --git a/confirmation/models.py b/confirmation/models.py index 8beea4b7e1..90fac69d66 100644 --- a/confirmation/models.py +++ b/confirmation/models.py @@ -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: