-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[Performance] Improve getOrderedReportIDs performance
#43539
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
Merged
mountiny
merged 6 commits into
Expensify:main
from
software-mansion-labs:@kosmydel/perf/mini-reports
Jun 13, 2024
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
59e5f83
draft: measure times
kosmydel 57771ff
feat: do not copy reports
kosmydel aa2f789
cleanup: remove redundant timings
kosmydel 25df8db
Merge branch 'main' into @kosmydel/perf/mini-reports
kosmydel 11af4fd
cleanup: remove timings
kosmydel cfaaf5c
address review: add JSDoc
kosmydel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,6 +62,16 @@ function compareStringDates(a: string, b: string): 0 | 1 | -1 { | |
| return 0; | ||
| } | ||
|
|
||
| /** | ||
| * A mini report object that contains only the necessary information to sort reports. | ||
| * This is used to avoid copying the entire report object and only the necessary information. | ||
| */ | ||
| type MiniReport = { | ||
|
Contributor
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 think we could have called this as MinimalSidebarReport or something like that to indicate this is specifically the minimum we need for the Sidebar, but NAB |
||
| reportID?: string; | ||
| displayName: string; | ||
| lastVisibleActionCreated?: string; | ||
| }; | ||
|
|
||
| /** | ||
| * @returns An array of reportIDs sorted in the proper order | ||
| */ | ||
|
|
@@ -132,10 +142,10 @@ function getOrderedReportIDs( | |
| // 4. Archived reports | ||
| // - Sorted by lastVisibleActionCreated in default (most recent) view mode | ||
| // - Sorted by reportDisplayName in GSD (focus) view mode | ||
| const pinnedAndGBRReports: Array<OnyxEntry<Report>> = []; | ||
| const draftReports: Array<OnyxEntry<Report>> = []; | ||
| const nonArchivedReports: Array<OnyxEntry<Report>> = []; | ||
| const archivedReports: Array<OnyxEntry<Report>> = []; | ||
| const pinnedAndGBRReports: MiniReport[] = []; | ||
| const draftReports: MiniReport[] = []; | ||
| const nonArchivedReports: MiniReport[] = []; | ||
| const archivedReports: MiniReport[] = []; | ||
|
|
||
| if (currentPolicyID || policyMemberAccountIDs.length > 0) { | ||
| reportsToDisplay = reportsToDisplay.filter( | ||
|
|
@@ -144,24 +154,23 @@ function getOrderedReportIDs( | |
| } | ||
| // There are a few properties that need to be calculated for the report which are used when sorting reports. | ||
| reportsToDisplay.forEach((reportToDisplay) => { | ||
| let report = reportToDisplay as OnyxEntry<Report>; | ||
| if (report) { | ||
| report = { | ||
| ...report, | ||
| displayName: ReportUtils.getReportName(report), | ||
| }; | ||
| } | ||
| const report = reportToDisplay as OnyxEntry<Report>; | ||
| const miniReport: MiniReport = { | ||
| reportID: report?.reportID, | ||
| displayName: ReportUtils.getReportName(report), | ||
| lastVisibleActionCreated: report?.lastVisibleActionCreated, | ||
| }; | ||
|
|
||
| const isPinned = report?.isPinned ?? false; | ||
| const reportAction = ReportActionsUtils.getReportAction(report?.parentReportID ?? '', report?.parentReportActionID ?? ''); | ||
| if (isPinned || ReportUtils.requiresAttentionFromCurrentUser(report, reportAction)) { | ||
| pinnedAndGBRReports.push(report); | ||
| pinnedAndGBRReports.push(miniReport); | ||
| } else if (hasValidDraftComment(report?.reportID ?? '')) { | ||
| draftReports.push(report); | ||
| draftReports.push(miniReport); | ||
| } else if (ReportUtils.isArchivedRoom(report)) { | ||
| archivedReports.push(report); | ||
| archivedReports.push(miniReport); | ||
| } else { | ||
| nonArchivedReports.push(report); | ||
| nonArchivedReports.push(miniReport); | ||
| } | ||
| }); | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.