From b48c723bc44279711230decd1333fc8f3d6972f8 Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Fri, 31 Mar 2023 23:54:16 -0400 Subject: [PATCH] Optimize member autocomplete by using indexes and istartswith --- membershipworks/admin.py | 2 +- membershipworks/models.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/membershipworks/admin.py b/membershipworks/admin.py index 836f5ea..4f0f5dc 100644 --- a/membershipworks/admin.py +++ b/membershipworks/admin.py @@ -20,7 +20,7 @@ class MemberFlagInline(admin.TabularInline): @admin.register(Member) class MemberAdmin(ReadOnlyAdmin): - search_fields = ["account_name"] + search_fields = ["^first_name", "^last_name", "^account_name"] inlines = [MemberFlagInline] diff --git a/membershipworks/models.py b/membershipworks/models.py index 77c7fed..e9efbaf 100644 --- a/membershipworks/models.py +++ b/membershipworks/models.py @@ -163,6 +163,11 @@ class Member(models.Model): managed = False db_table = "members" ordering = ("first_name", "last_name") + indexes = [ + models.Index(fields=["account_name"]), + models.Index(fields=["first_name"]), + models.Index(fields=["last_name"]), + ] def sanitized_mailbox(self, name_ext: str = "", use_volunteer=False) -> str: if use_volunteer and self.volunteer_email: