Optimize member autocomplete by using indexes and istartswith

This commit is contained in:
Adam Goldsmith 2023-03-31 23:54:16 -04:00
parent 1eb3952ea1
commit b48c723bc4
2 changed files with 6 additions and 1 deletions

View File

@ -20,7 +20,7 @@ class MemberFlagInline(admin.TabularInline):
@admin.register(Member) @admin.register(Member)
class MemberAdmin(ReadOnlyAdmin): class MemberAdmin(ReadOnlyAdmin):
search_fields = ["account_name"] search_fields = ["^first_name", "^last_name", "^account_name"]
inlines = [MemberFlagInline] inlines = [MemberFlagInline]

View File

@ -163,6 +163,11 @@ class Member(models.Model):
managed = False managed = False
db_table = "members" db_table = "members"
ordering = ("first_name", "last_name") 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: def sanitized_mailbox(self, name_ext: str = "", use_volunteer=False) -> str:
if use_volunteer and self.volunteer_email: if use_volunteer and self.volunteer_email: