people: Revert to using `ignore_missing` parameter.

We revert to use `ignore_missing` parameter for `maybe_get_user_by_id`
function to avoid sending unnecessary `blueslip.error()` calls to
sentry.
This commit is contained in:
Lalit Singh 2023-08-02 23:34:25 +05:30 committed by Anders Kaseorg
parent bfd52ccd68
commit 2893685890
4 changed files with 4 additions and 5 deletions

View File

@ -121,8 +121,8 @@ export function get_by_user_id(user_id: number): User {
} }
// This is type unsafe version of get_by_user_id for the callers that expects undefined values. // This is type unsafe version of get_by_user_id for the callers that expects undefined values.
export function maybe_get_user_by_id(user_id: number): User | undefined { export function maybe_get_user_by_id(user_id: number, ignore_missing = false): User | undefined {
if (!people_by_user_id_dict.has(user_id)) { if (!people_by_user_id_dict.has(user_id) && !ignore_missing) {
blueslip.error("Unknown user_id in maybe_get_user_by_id", {user_id}); blueslip.error("Unknown user_id in maybe_get_user_by_id", {user_id});
return undefined; return undefined;
} }

View File

@ -175,7 +175,7 @@ export function set_info(presences, server_timestamp) {
// reload_state.is_in_progress, because races where presence // reload_state.is_in_progress, because races where presence
// returns data on users not yet received via the server_events // returns data on users not yet received via the server_events
// system are common in both situations. // system are common in both situations.
const person = people.maybe_get_user_by_id(user_id); const person = people.maybe_get_user_by_id(user_id, true);
if (person === undefined) { if (person === undefined) {
if (!(watchdog.suspects_user_is_offline() || reload_state.is_in_progress())) { if (!(watchdog.suspects_user_is_offline() || reload_state.is_in_progress())) {
// If we're online, and we get a user who we don't // If we're online, and we get a user who we don't

View File

@ -107,7 +107,7 @@ export const update_elements = ($content) => {
// mention text to show the user's current name, // mention text to show the user's current name,
// assuming that you're not searching for text // assuming that you're not searching for text
// inside the highlight. // inside the highlight.
const person = people.maybe_get_user_by_id(user_id); const person = people.maybe_get_user_by_id(user_id, true);
if (person !== undefined) { if (person !== undefined) {
// Note that person might be undefined in some // Note that person might be undefined in some
// unpleasant corner cases involving data import. // unpleasant corner cases involving data import.

View File

@ -95,7 +95,6 @@ test("unknown user", ({override}) => {
const presences = {}; const presences = {};
presences[unknown_user_id.toString()] = "does-not-matter"; presences[unknown_user_id.toString()] = "does-not-matter";
blueslip.expect("error", "Unknown user_id in maybe_get_user_by_id", 3);
blueslip.expect("error", "Unknown user ID in presence data"); blueslip.expect("error", "Unknown user ID in presence data");
presence.set_info(presences, now); presence.set_info(presences, now);