Skip to content

Commit

Permalink
Merge pull request #40193 from janicduplessis/@janic/getsearchterm
Browse files Browse the repository at this point in the history
Improve getSearchText perf
  • Loading branch information
roryabraham authored Apr 25, 2024
2 parents 417a673 + fc35658 commit cbe82b6
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 @@ -434,12 +434,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 @@ -448,22 +446,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 @@ -477,16 +470,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 cbe82b6

Please sign in to comment.