Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

typeahead_helper: Cache diacritic-less names for performance.

apoorvapendse378dc7a97deb
diff --git a/web/src/composebox_typeahead.ts b/web/src/composebox_typeahead.ts
index 19c521eb851..8c39079cc94 100644
--- a/web/src/composebox_typeahead.ts
+++ b/web/src/composebox_typeahead.ts
@@ -671,8 +671,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[];
diff --git a/web/src/typeahead_helper.ts b/web/src/typeahead_helper.ts
index da55e01ba6d..841fe675d3b 100644
--- a/web/src/typeahead_helper.ts
+++ b/web/src/typeahead_helper.ts
@@ -1063,16 +1063,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;
}