Skip to content

Commit

Permalink
Improve getSearchText perf
Browse files Browse the repository at this point in the history
  • Loading branch information
janicduplessis committed Apr 12, 2024
1 parent dff9542 commit fc35658
Showing 1 changed file with 10 additions and 27 deletions.
37 changes: 10 additions & 27 deletions src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,12 +432,10 @@ function uniqFast(items: string[]): string[] {

/**
* Returns a string with all relevant search terms.
* Default should be serachable by policy/domain name but not by participants.
*
* This method must be incredibly performant. It was found to be a big performance bottleneck
* when dealing with accounts that have thousands of reports. For loops are more efficient than _.each
* Array.prototype.push.apply is faster than using the spread operator, and concat() is faster than push().
* Array.prototype.push.apply is faster than using the spread operator.
*/
function getSearchText(
report: OnyxEntry<Report>,
Expand All @@ -446,22 +444,17 @@ function getSearchText(
isChatRoomOrPolicyExpenseChat: boolean,
isThread: boolean,
): string {
let searchTerms: string[] = [];

if (!isChatRoomOrPolicyExpenseChat) {
for (const personalDetail of personalDetailList) {
if (personalDetail.login) {
// The regex below is used to remove dots only from the local part of the user email (local-part@domain)
// so that we can match emails that have dots without explicitly writing the dots (e.g: fistlast@domain will match first.last@domain)
// More info https://github.com/Expensify/App/issues/8007
searchTerms = searchTerms.concat([
PersonalDetailsUtils.getDisplayNameOrDefault(personalDetail, '', false),
personalDetail.login,
personalDetail.login.replace(/\.(?=[^\s@]*@)/g, ''),
]);
}
const searchTerms: string[] = [];

for (const personalDetail of personalDetailList) {
if (personalDetail.login) {
// The regex below is used to remove dots only from the local part of the user email (local-part@domain)
// so that we can match emails that have dots without explicitly writing the dots (e.g: fistlast@domain will match first.last@domain)
// More info https://github.com/Expensify/App/issues/8007
searchTerms.push(PersonalDetailsUtils.getDisplayNameOrDefault(personalDetail, '', false), personalDetail.login, personalDetail.login.replace(/\.(?=[^\s@]*@)/g, ''));
}
}

if (report) {
Array.prototype.push.apply(searchTerms, reportName.split(/[,\s]/));

Expand All @@ -475,16 +468,6 @@ function getSearchText(
const chatRoomSubtitle = ReportUtils.getChatRoomSubtitle(report);

Array.prototype.push.apply(searchTerms, chatRoomSubtitle?.split(/[,\s]/) ?? ['']);
} else {
const visibleChatMemberAccountIDs = report.visibleChatMemberAccountIDs ?? [];
if (allPersonalDetails) {
for (const accountID of visibleChatMemberAccountIDs) {
const login = allPersonalDetails[accountID]?.login;
if (login) {
searchTerms = searchTerms.concat(login);
}
}
}
}
}

Expand Down

0 comments on commit fc35658

Please sign in to comment.