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): class Contact(TimeStampedModel):
"""Contact information follows a similar pattern for each contact.""" """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( user = models.OneToOneField(
"registrar.User", "registrar.User",
null=True, null=True,
@ -19,7 +26,6 @@ class Contact(TimeStampedModel):
null=True, null=True,
blank=True, blank=True,
verbose_name="first name", verbose_name="first name",
db_index=True,
) )
middle_name = models.CharField( middle_name = models.CharField(
null=True, null=True,
@ -29,7 +35,6 @@ class Contact(TimeStampedModel):
null=True, null=True,
blank=True, blank=True,
verbose_name="last name", verbose_name="last name",
db_index=True,
) )
title = models.CharField( title = models.CharField(
null=True, null=True,
@ -39,13 +44,11 @@ class Contact(TimeStampedModel):
email = models.EmailField( email = models.EmailField(
null=True, null=True,
blank=True, blank=True,
db_index=True,
max_length=320, max_length=320,
) )
phone = PhoneNumberField( phone = PhoneNumberField(
null=True, null=True,
blank=True, blank=True,
db_index=True,
) )
def _get_all_relations(self): def _get_all_relations(self):

View file

@ -65,6 +65,13 @@ class Domain(TimeStampedModel, DomainHelper):
domain meets the required checks. domain meets the required checks.
""" """
class Meta:
"""Contains meta information about this class"""
indexes = [
models.Index(fields=["name"]),
]
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
self._cache = {} self._cache = {}
super(Domain, self).__init__(*args, **kwargs) 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 the domain request once approved, so copying them that way we can make changes
after its approved. Most fields here are copied from DomainRequest.""" 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 StateTerritoryChoices = DomainRequest.StateTerritoryChoices
# use the short names in Django admin # use the short names in Django admin
@ -120,7 +128,6 @@ class DomainInformation(TimeStampedModel):
organization_name = models.CharField( organization_name = models.CharField(
null=True, null=True,
blank=True, blank=True,
db_index=True,
) )
address_line1 = models.CharField( address_line1 = models.CharField(
null=True, null=True,
@ -147,7 +154,6 @@ class DomainInformation(TimeStampedModel):
max_length=10, max_length=10,
null=True, null=True,
blank=True, blank=True,
db_index=True,
verbose_name="zip code", verbose_name="zip code",
) )
urbanization = models.CharField( urbanization = models.CharField(

View file

@ -24,6 +24,15 @@ logger = logging.getLogger(__name__)
class DomainRequest(TimeStampedModel): class DomainRequest(TimeStampedModel):
"""A registrant's domain request for a new domain.""" """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 # https://django-auditlog.readthedocs.io/en/latest/usage.html#object-history
# If we note any performace degradation due to this addition, # If we note any performace degradation due to this addition,
# we can query the auditlogs table in admin.py and add the results to # 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( organization_name = models.CharField(
null=True, null=True,
blank=True, blank=True,
db_index=True,
) )
address_line1 = models.CharField( address_line1 = models.CharField(
@ -566,7 +574,6 @@ class DomainRequest(TimeStampedModel):
null=True, null=True,
blank=True, blank=True,
verbose_name="zip code", verbose_name="zip code",
db_index=True,
) )
urbanization = models.CharField( urbanization = models.CharField(
null=True, null=True,

View file

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

View file

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

View file

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