Skip to content

Commit

Permalink
Merge pull request #28000 from margelo/@szymon/compare_strings
Browse files Browse the repository at this point in the history
Speedup `getOrderedReportIDs` by compering strings instead of Dates objects
  • Loading branch information
mountiny authored Sep 25, 2023
2 parents 1c08ab3 + adcb854 commit 6461bfa
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/libs/SidebarUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ function isSidebarLoadedReady() {
return sidebarIsReadyPromise;
}

function compareStringDates(stringA, stringB) {
if (stringA < stringB) {
return -1;
}
if (stringA > stringB) {
return 1;
}
return 0;
}

function setIsSidebarLoadedReady() {
resolveSidebarIsReadyPromise();
}
Expand Down Expand Up @@ -184,12 +194,13 @@ function getOrderedReportIDs(currentReportId, allReportsDict, betas, policies, p
pinnedReports.sort((a, b) => a.displayName.toLowerCase().localeCompare(b.displayName.toLowerCase()));
outstandingIOUReports.sort((a, b) => b.iouReportAmount - a.iouReportAmount || a.displayName.toLowerCase().localeCompare(b.displayName.toLowerCase()));
draftReports.sort((a, b) => a.displayName.toLowerCase().localeCompare(b.displayName.toLowerCase()));

if (isInDefaultMode) {
nonArchivedReports.sort(
(a, b) => new Date(b.lastVisibleActionCreated) - new Date(a.lastVisibleActionCreated) || a.displayName.toLowerCase().localeCompare(b.displayName.toLowerCase()),
(a, b) => compareStringDates(b.lastVisibleActionCreated, a.lastVisibleActionCreated) || a.displayName.toLowerCase().localeCompare(b.displayName.toLowerCase()),
);
// For archived reports ensure that most recent reports are at the top by reversing the order
archivedReports.sort((a, b) => new Date(a.lastVisibleActionCreated) - new Date(b.lastVisibleActionCreated));
archivedReports.sort((a, b) => compareStringDates(b.lastVisibleActionCreated, a.lastVisibleActionCreated));
} else {
nonArchivedReports.sort((a, b) => a.displayName.toLowerCase().localeCompare(b.displayName.toLowerCase()));
archivedReports.sort((a, b) => a.displayName.toLowerCase().localeCompare(b.displayName.toLowerCase()));
Expand Down

0 comments on commit 6461bfa

Please sign in to comment.