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

Speedup getOrderedReportIDs by compering strings instead of Dates objects #28000

Merged
merged 8 commits into from
Sep 25, 2023
Merged
Changes from 5 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
13 changes: 11 additions & 2 deletions src/libs/SidebarUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,21 @@ 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()));
const compareStringDates = (stringA, stringB) => {
mountiny marked this conversation as resolved.
Show resolved Hide resolved
if (stringA < stringB) {
return 1;
}
if (stringA > stringB) {
return -1;
}
return 0;
};
if (isInDefaultMode) {
nonArchivedReports.sort(
(a, b) => new Date(b.lastVisibleActionCreated) - new Date(a.lastVisibleActionCreated) || a.displayName.toLowerCase().localeCompare(b.displayName.toLowerCase()),
(a, b) => compareStringDates(a.lastVisibleActionCreated, b.lastVisibleActionCreated) || a.displayName.toLowerCase().localeCompare(b.displayName.toLowerCase()),
Copy link
Contributor

Choose a reason for hiding this comment

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

here we had new Date(b.lastVisibleActionCreated) - new Date(a.lastVisibleActionCreated)
Please change to: compareStringDates(b.lastVisibleActionCreated, a.lastVisibleActionCreated)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That would reverse the order.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, thats the point how it was done before

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Then tests won't pass. I can change values in the comparator function but it doesn't make sense for me.
(a, b) => cmp(a, b) is cleaner then (a, b) => cmp(b, a)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah I see what you meant. Once we extract it outside of the function it will make sense

);
// 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(a.lastVisibleActionCreated, b.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
Loading