Skip to content

Commit f6de195

Browse files
authored
Merge pull request #43539 from software-mansion-labs/@kosmydel/perf/mini-reports
[Performance] Improve `getOrderedReportIDs` performance
2 parents 3d3c95b + cfaaf5c commit f6de195

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

src/libs/SidebarUtils.ts

+24-15
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@ function compareStringDates(a: string, b: string): 0 | 1 | -1 {
6262
return 0;
6363
}
6464

65+
/**
66+
* A mini report object that contains only the necessary information to sort reports.
67+
* This is used to avoid copying the entire report object and only the necessary information.
68+
*/
69+
type MiniReport = {
70+
reportID?: string;
71+
displayName: string;
72+
lastVisibleActionCreated?: string;
73+
};
74+
6575
/**
6676
* @returns An array of reportIDs sorted in the proper order
6777
*/
@@ -132,10 +142,10 @@ function getOrderedReportIDs(
132142
// 4. Archived reports
133143
// - Sorted by lastVisibleActionCreated in default (most recent) view mode
134144
// - Sorted by reportDisplayName in GSD (focus) view mode
135-
const pinnedAndGBRReports: Array<OnyxEntry<Report>> = [];
136-
const draftReports: Array<OnyxEntry<Report>> = [];
137-
const nonArchivedReports: Array<OnyxEntry<Report>> = [];
138-
const archivedReports: Array<OnyxEntry<Report>> = [];
145+
const pinnedAndGBRReports: MiniReport[] = [];
146+
const draftReports: MiniReport[] = [];
147+
const nonArchivedReports: MiniReport[] = [];
148+
const archivedReports: MiniReport[] = [];
139149

140150
if (currentPolicyID || policyMemberAccountIDs.length > 0) {
141151
reportsToDisplay = reportsToDisplay.filter(
@@ -144,24 +154,23 @@ function getOrderedReportIDs(
144154
}
145155
// There are a few properties that need to be calculated for the report which are used when sorting reports.
146156
reportsToDisplay.forEach((reportToDisplay) => {
147-
let report = reportToDisplay as OnyxEntry<Report>;
148-
if (report) {
149-
report = {
150-
...report,
151-
displayName: ReportUtils.getReportName(report),
152-
};
153-
}
157+
const report = reportToDisplay as OnyxEntry<Report>;
158+
const miniReport: MiniReport = {
159+
reportID: report?.reportID,
160+
displayName: ReportUtils.getReportName(report),
161+
lastVisibleActionCreated: report?.lastVisibleActionCreated,
162+
};
154163

155164
const isPinned = report?.isPinned ?? false;
156165
const reportAction = ReportActionsUtils.getReportAction(report?.parentReportID ?? '', report?.parentReportActionID ?? '');
157166
if (isPinned || ReportUtils.requiresAttentionFromCurrentUser(report, reportAction)) {
158-
pinnedAndGBRReports.push(report);
167+
pinnedAndGBRReports.push(miniReport);
159168
} else if (hasValidDraftComment(report?.reportID ?? '')) {
160-
draftReports.push(report);
169+
draftReports.push(miniReport);
161170
} else if (ReportUtils.isArchivedRoom(report)) {
162-
archivedReports.push(report);
171+
archivedReports.push(miniReport);
163172
} else {
164-
nonArchivedReports.push(report);
173+
nonArchivedReports.push(miniReport);
165174
}
166175
});
167176

0 commit comments

Comments
 (0)