user_pill: Avoid unnecessary array allocations.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2024-05-13 17:16:33 -07:00 committed by Tim Abbott
parent c0c852046d
commit 2e8fdab896

View File

@ -26,16 +26,11 @@ export function create_item_from_email(
pill_config?: InputPillConfig | undefined,
): InputPillItem<UserPill> | undefined {
// For normal Zulip use, we need to validate the email for our realm.
const filtered_current_items = current_items.flatMap((item) =>
item.type === "user" ? item : [],
);
const user = people.get_by_email(email);
if (!user) {
if (realm.realm_is_zephyr_mirror_realm) {
const existing_emails = filtered_current_items.map((item) => item.email);
if (existing_emails.includes(email)) {
if (current_items.some((item) => item.type === "user" && item.email === email)) {
return undefined;
}
@ -57,9 +52,7 @@ export function create_item_from_email(
return undefined;
}
const existing_ids = filtered_current_items.map((item) => item.user_id);
if (existing_ids.includes(user.user_id)) {
if (current_items.some((item) => item.type === "user" && item.user_id === user.user_id)) {
return undefined;
}