perf: remove redundant O(employees) member scans#96080
Draft
adhorodyski wants to merge 3 commits into
Draft
Conversation
getPolicyEmployeeAccountIDs enumerated the full policy employeeList (~21k entries on large accounts) on every SettlementButton and usePaymentOptions render, feeding doesReportBelongToWorkspace — a helper built for the removed workspace switcher whose expensive DM branch is unreachable at every remaining call site. Replace both with field comparisons (isConciergeChatReport || isPolicyRelatedReport), harden isPolicyRelatedReport against undefined/_FAKE_ policyIDs, and switch composer mention weighting to an O(1) employeeList lookup.
# Conflicts: # src/hooks/usePaymentOptions.ts # src/pages/inbox/report/ReportActionCompose/SuggestionMention.tsx # tests/unit/PolicyUtilsTest.ts # tests/unit/SuggestionMentionTest.tsx
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.
|
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. Delightful! Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
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
Every rendered
SettlementButton(report header, each report preview, each Pay row on the Reports page) calledgetPolicyEmployeeAccountIDs, which walks the whole policy employee list. On a ~21k-member policy that is a 21k-entry array built per button, per render — and the result was thrown away unused.The array fed one function:
doesReportBelongToWorkspace. It was built for the workspace switcher (its call site was removed in #79940) and only reads the array for DMs — a case that cannot occur at any of its remaining call sites, because every caller derivespolicyIDfrom the report chain itself. The payment code only uses the boolean to pick theNVP_LAST_PAYMENT_METHODkey, and that NVP is only ever written keyed byiouReport.policyID.This PR deletes
doesReportBelongToWorkspaceandgetPolicyEmployeeAccountIDsand replaces them with two field comparisons (isConciergeChatReport || isPolicyRelatedReport). Composer mention weighting now checkspolicy.employeeList[login]directly (O(1)) instead of scanning the array per suggestion.usePaymentOptionsalso drops a now-unused whole-policy subscription.This does not break userspace. Two places differ on purpose:
isPolicyRelatedReportnow returnsfalsefor an undefined or_FAKE_policyID. Before, an undefined ID matched every report that also had no policyID, souseTransactionViolationOfWorkspacecomputed archive data before any delete was started. The delete flow itself is unchanged.employeeList[login]by exact key. The old path went through a lowercased email cache. If a key's casing ever differs from the login, that person sorts one tier lower in suggestions — nothing else changes.Fixed Issues
$ https://github.com/Expensify/Expensify/issues/591294
PROPOSAL:
Tests
@followed by a few letters. Verify report participants rank first, workspace members second, others last.@. Verify suggestions are plain alphabetical (no member weighting).Offline tests
N/A (no network-dependent logic changed).
QA Steps
Same as tests.
@followed by a few letters. Verify report participants rank first, workspace members second, others last.@. Verify suggestions are plain alphabetical (no member weighting).PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectionAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))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
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari