Repository navigation
[NoQA] perf: check cheap conditions first in merge, self-approval, held expense, and unread checks - #108614
Draft
mountiny wants to merge 1 commit into
Draft
[NoQA] perf: check cheap conditions first in merge, self-approval, held expense, and unread checks#108614mountiny wants to merge 1 commit into
mountiny wants to merge 1 commit into
Conversation
Open
1 task
Codecov Report❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.
|
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Explanation of Change
A second scan for the pattern in Perf: check cheap conditions before expensive ones in report, option list, and bulk action paths found more places that run an expensive call before a cheap check that can make its result irrelevant. Each one saves less than the main cases, so they go together in this PR:
isMergeActionandisMergeActionForSelectedTransactionsnow checkisSubmitAndCloseandisInstantSubmitEnabledbeforehasOnlyNonReimbursableTransactions, which loops over the report's expenses.canAddTransactionalready uses this order.shouldBlockSubmitDueToPreventSelfApprovalnow looks up the next approver only when it can change the result. Reports that are neither open nor processing skip the lookup, and so do processing reports where the manager is the owner. The lookup scans the approval rules.getReportPrimaryActionand the submit, approve, and pay to-do buckets inTodosUtilsnow check the held state, which is already computed, beforeisApproveAction,isSubmitAction, andisPrimaryPayAction. Reports where every expense is held skip those checks.getIsUnreadReportForInboxTaband the focus mode branch ofreasonForReportToBeInOptionListnow check whether the report is muted beforeisUnread. Focus mode also skips the transaction thread lookup for muted reports.Every reordered check has no side effects, so every result stays the same.
Automated tests
Each test below fails on
mainand passes with this change.tests/unit/ReportSecondaryActionUtilsTest.tsassert thathasOnlyNonReimbursableTransactionsdoes not run outside Submit & Close workspaces.tests/unit/ReportUtilsTest.tsasserts that an approved report never lists the approval rules.tests/unit/ReportPrimaryActionUtilsTest.ts, and three tests intests/unit/TodosUtilsTest.ts, assert that the approve, submit, and pay checks do not run for reports where every expense is held.tests/unit/SidebarUtilsTest.tsasserts thatisUnreaddoes not run for a muted chat, and a test intests/unit/ReportUtilsTest.tsasserts that focus mode does not look up the transaction thread of a muted report.npx jest --runTestsByPath tests/unit/ReportSecondaryActionUtilsTest.ts tests/unit/ReportUtilsTest.ts tests/unit/ReportPrimaryActionUtilsTest.ts tests/unit/TodosUtilsTest.ts tests/unit/SidebarUtilsTest.ts tests/unit/NextStepUtilsTest.ts tests/unit/useTodoCountsTest.tsx tests/unit/HomeTodoReviewUtilsTest.ts tests/ui/components/SubmitActionButtonTest.tsx(2509 tests).npm run lint-changedandnpm run spell-changed.npm run typecheckreports no errors in the changed files.Fixed Issues
$ #108608
PROPOSAL:
Tests
Offline tests
Same as Tests. The reordered checks read only local data, so offline behavior does not change.
QA Steps
No QA. This PR only changes the order of checks that have no side effects, so nothing changes for the user. The automated tests above cover the change.
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectionAvatar, I verified the components usingAvatarare working as expected)npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Not tested on this platform. This PR only reorders checks that have no side effects, and the unit tests above cover it.
Android: mWeb Chrome
Not tested on this platform. This PR only reorders checks that have no side effects, and the unit tests above cover it.
iOS: Native
Not tested on this platform. This PR only reorders checks that have no side effects, and the unit tests above cover it.
iOS: mWeb Safari
Not tested on this platform. This PR only reorders checks that have no side effects, and the unit tests above cover it.
MacOS: Chrome / Safari
Not tested on this platform. This PR only reorders checks that have no side effects, and the unit tests above cover it.