Remove db_index, add meta index

This commit is contained in:
zandercymatics 2024-05-06 14:19:25 -06:00
parent aa9ec2d716
commit 24a18f1562
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
7 changed files with 31 additions and 13 deletions

View file

@ -8,6 +8,13 @@ from phonenumber_field.modelfields import PhoneNumberField # type: ignore
class Contact(TimeStampedModel):
"""Contact information follows a similar pattern for each contact."""
class Meta:
"""Contains meta information about this class"""
indexes = [
models.Index(fields=["user"]),
models.Index(fields=["email"]),
]
user = models.OneToOneField(
"registrar.User",
null=True,
@ -19,7 +26,6 @@ class Contact(TimeStampedModel):
null=True,
blank=True,
verbose_name="first name",
db_index=True,
)
middle_name = models.CharField(
null=True,
@ -29,7 +35,6 @@ class Contact(TimeStampedModel):
null=True,
blank=True,
verbose_name="last name",
db_index=True,
)
title = models.CharField(
null=True,
@ -39,13 +44,11 @@ class Contact(TimeStampedModel):
email = models.EmailField(
null=True,
blank=True,
db_index=True,
max_length=320,
)
phone = PhoneNumberField(
null=True,
blank=True,
db_index=True,
)
def _get_all_relations(self):

View file

@ -65,6 +65,13 @@ class Domain(TimeStampedModel, DomainHelper):
domain meets the required checks.
"""
class Meta:
"""Contains meta information about this class"""
indexes = [
models.Index(fields=["name"]),
]
def __init__(self, *args, **kwargs):
self._cache = {}
super(Domain, self).__init__(*args, **kwargs)

View file

@ -22,6 +22,14 @@ class DomainInformation(TimeStampedModel):
the domain request once approved, so copying them that way we can make changes
after its approved. Most fields here are copied from DomainRequest."""
class Meta:
"""Contains meta information about this class"""
indexes = [
models.Index(fields=["domain"]),
models.Index(fields=["domain_request"]),
models.Index(fields=["generic_org_type"]),
]
StateTerritoryChoices = DomainRequest.StateTerritoryChoices
# use the short names in Django admin
@ -120,7 +128,6 @@ class DomainInformation(TimeStampedModel):
organization_name = models.CharField(
null=True,
blank=True,
db_index=True,
)
address_line1 = models.CharField(
null=True,
@ -147,7 +154,6 @@ class DomainInformation(TimeStampedModel):
max_length=10,
null=True,
blank=True,
db_index=True,
verbose_name="zip code",
)
urbanization = models.CharField(

View file

@ -24,6 +24,15 @@ logger = logging.getLogger(__name__)
class DomainRequest(TimeStampedModel):
"""A registrant's domain request for a new domain."""
class Meta:
"""Contains meta information about this class"""
indexes = [
models.Index(fields=["requested_domain"]),
models.Index(fields=["approved_domain"]),
models.Index(fields=["status"]),
models.Index(fields=["generic_org_type"]),
]
# https://django-auditlog.readthedocs.io/en/latest/usage.html#object-history
# If we note any performace degradation due to this addition,
# we can query the auditlogs table in admin.py and add the results to
@ -537,7 +546,6 @@ class DomainRequest(TimeStampedModel):
organization_name = models.CharField(
null=True,
blank=True,
db_index=True,
)
address_line1 = models.CharField(
@ -566,7 +574,6 @@ class DomainRequest(TimeStampedModel):
null=True,
blank=True,
verbose_name="zip code",
db_index=True,
)
urbanization = models.CharField(
null=True,

View file

@ -59,7 +59,6 @@ class TransitionDomain(TimeStampedModel):
null=True,
blank=True,
help_text="Organization name",
db_index=True,
)
federal_type = models.CharField(
max_length=50,
@ -85,7 +84,6 @@ class TransitionDomain(TimeStampedModel):
blank=True,
help_text="First name / given name",
verbose_name="first name",
db_index=True,
)
middle_name = models.CharField(
null=True,
@ -136,7 +134,6 @@ class TransitionDomain(TimeStampedModel):
blank=True,
verbose_name="zip code",
help_text="Zip code",
db_index=True,
)
def __str__(self):

View file

@ -70,7 +70,6 @@ class User(AbstractUser):
null=True,
blank=True,
help_text="Phone",
db_index=True,
)
verification_type = models.CharField(

View file

@ -9,7 +9,6 @@ class VerifiedByStaff(TimeStampedModel):
email = models.EmailField(
null=False,
blank=False,
db_index=True,
)
requestor = models.ForeignKey(