typeahead_helper: Cache diacritic-less names for performance.

This code path now uses the full name with removed diacritics cache,
just like the right sidebar buddy list search.

This fixes a major performance issue with trying to mention users in
organizations with 10,000s of total users.

Fixes:
https://chat.zulip.org/#narrow/channel/9-issues/topic/Mention.20typeahead.20performance/with/2157415.
(cherry picked from commit 378dc7a97d)
This commit is contained in:
apoorvapendse
2025-04-18 12:48:59 +05:30
committed by Tim Abbott
parent ff4860ddbc
commit 496f793dae
2 changed files with 36 additions and 8 deletions

View File

@@ -670,8 +670,12 @@ export function get_person_suggestions(
})),
];
}
return person_items.filter((item) => typeahead_helper.query_matches_person(query, item));
const should_remove_diacritics = people.should_remove_diacritics_for_query(
query.toLowerCase(),
);
return person_items.filter((item) =>
typeahead_helper.query_matches_person(query, item, should_remove_diacritics),
);
}
let groups: UserGroup[];

View File

@@ -920,16 +920,40 @@ export function rewire_sort_user_groups(value: typeof sort_user_groups): void {
export function query_matches_person(
query: string,
person: UserPillData | UserOrMentionPillData,
should_remove_diacritics: boolean | undefined = undefined,
): boolean {
if (typeahead.query_matches_string_in_order(query, person.user.full_name, " ")) {
if (
person.type === "broadcast" &&
typeahead.query_matches_string_in_order(query, person.user.full_name, " ")
) {
return true;
}
if (person.type === "user" && Boolean(person.user.delivery_email)) {
return typeahead.query_matches_string_in_order(
query,
people.get_visible_email(person.user),
" ",
if (person.type === "user") {
query = query.toLowerCase();
should_remove_diacritics ??= people.should_remove_diacritics_for_query(query);
const full_name = people.maybe_remove_diacritics_from_name(
person.user,
should_remove_diacritics,
);
if (
typeahead.query_matches_string_in_order_assume_canonicalized(
query,
full_name.toLowerCase(),
" ",
)
) {
return true;
}
if (person.user.delivery_email) {
return typeahead.query_matches_string_in_order(
query,
people.get_visible_email(person.user),
" ",
);
}
}
return false;
}