Skip to content

Commit

Permalink
user_pill: Avoid unnecessary array allocations.
Browse files Browse the repository at this point in the history
Signed-off-by: Anders Kaseorg <anders@zulip.com>
  • Loading branch information
andersk authored and timabbott committed May 14, 2024
1 parent c0c8520 commit 2e8fdab
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions web/src/user_pill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down

0 comments on commit 2e8fdab

Please sign in to comment.