Skip to content
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

improve isConciergeChatReport performance #47043

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1140,8 +1140,16 @@ function isSystemChat(report: OnyxEntry<Report>): boolean {
* Only returns true if this is our main 1:1 DM report with Concierge.
*/
function isConciergeChatReport(report: OnyxInputOrEntry<Report>): boolean {
const participantAccountIDs = Object.keys(report?.participants ?? {}).filter((accountID) => Number(accountID) !== currentUserAccountID);
return participantAccountIDs.length === 1 && Number(participantAccountIDs[0]) === CONST.ACCOUNT_ID.CONCIERGE && !isThread(report);
if (!report?.participants || isThread(report)) {
return false;
}

const participantAccountIDs = new Set(Object.keys(report.participants));
if (participantAccountIDs.size !== 2) {
danieldoglas marked this conversation as resolved.
Show resolved Hide resolved
return false;
}

return participantAccountIDs.has(CONST.ACCOUNT_ID.CONCIERGE.toString());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure about the impact of it but the conversion to string can happen only once, outside of this function's body

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This improvement is minor, but can have a noticeable impact on heavy accounts as this function is called frequently.

}

function findSelfDMReportID(): string | undefined {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/ReportUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ describe('ReportUtils', () => {
});

const report: Report = {
...LHNTestUtils.getFakeReport([CONST.ACCOUNT_ID.CONCIERGE]),
...LHNTestUtils.getFakeReport([accountID, CONST.ACCOUNT_ID.CONCIERGE]),
};

expect(ReportUtils.isChatUsedForOnboarding(report)).toBeTruthy();
Expand Down
Loading