Allow searching members by shelf, prefetch_related search strings

utils.gen_search_strings() times

before: 1.4 s
after member shelves: 2.6 s
after prefetch_related: 0.7 s
This commit is contained in:
Tanner Collin 2023-08-20 22:08:17 +00:00
parent 342c6f0189
commit f3450b5991
2 changed files with 10 additions and 3 deletions

View File

@ -157,7 +157,7 @@ def gen_search_strings():
start = time.time() start = time.time()
search_strings = {} search_strings = {}
for m in models.Member.objects.order_by('-expire_date'): for m in models.Member.objects.order_by('-expire_date').prefetch_related('user__storage'):
string = '{} {} | {} {}'.format( string = '{} {} | {} {}'.format(
m.preferred_name, m.preferred_name,
m.last_name, m.last_name,
@ -166,11 +166,18 @@ def gen_search_strings():
) )
string += ' | ' + m.user.email string += ' | ' + m.user.email
if m.discourse_username:
string += ' | ' + m.discourse_username string += ' | ' + m.discourse_username
string += ' | ' + str(m.id) string += ' | ' + str(m.id)
for s in m.user.storage.all():
string += ' | ' + s.shelf_id
string = string.lower() string = string.lower()
search_strings[string] = m.id search_strings[string] = m.id
cache.set('search_strings', search_strings) cache.set('search_strings', search_strings)
logger.info('Generated search strings in %s s.', time.time() - start) logger.info('Generated search strings in %s s.', time.time() - start)

View File

@ -178,7 +178,7 @@ export function Members(props) {
<Container> <Container>
<Header size='large'>Member List</Header> <Header size='large'>Member List</Header>
<p>Search by name, email, Spacebar username, or member ID:</p> <p>Search by name, email, Spacebar username, member ID, or member shelf:</p>
<Input autoFocus focus icon='search' <Input autoFocus focus icon='search'
placeholder='Search...' placeholder='Search...'