-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: improve getDisplayNameForParticipant performance #45907
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1859,6 +1859,9 @@ function getPersonalDetailsForAccountID(accountID: number): Partial<PersonalDeta | |
} | ||
|
||
const hiddenTranslation = Localize.translateLocal('common.hidden'); | ||
|
||
const phoneNumberCache: Record<string, string> = {}; | ||
|
||
/** | ||
* Get the displayName for a single report participant. | ||
*/ | ||
|
@@ -1868,8 +1871,20 @@ function getDisplayNameForParticipant(accountID?: number, shouldUseShortForm = f | |
} | ||
|
||
const personalDetails = getPersonalDetailsForAccountID(accountID); | ||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing | ||
const formattedLogin = LocalePhoneNumber.formatPhoneNumber(personalDetails.login || ''); | ||
if (!personalDetails) { | ||
return ''; | ||
} | ||
Comment on lines
+1874
to
+1876
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like this early return was added in the PR. What is its impact on the function flow? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added it to avoid unnecessary calculations and function calls if |
||
|
||
const login = personalDetails.login ?? ''; | ||
|
||
// Check if the phone number is already cached | ||
let formattedLogin = phoneNumberCache[login]; | ||
if (!formattedLogin) { | ||
formattedLogin = LocalePhoneNumber.formatPhoneNumber(login); | ||
// Store the formatted phone number in the cache | ||
phoneNumberCache[login] = formattedLogin; | ||
} | ||
|
||
// This is to check if account is an invite/optimistically created one | ||
// and prevent from falling back to 'Hidden', so a correct value is shown | ||
// when searching for a new user | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there any other functions we could use this cache in this Utils file? Lets see if we can use it there in next PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the way forward for this would be to reuse the global cache proposed by Kacper in the other PR so we can swap every usage with this cached one in one go.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This appears to be the only place in this file where the
formatPhoneNumber
is used