Repository navigation
perf: Reuse one policy list across selected reports in the change-workspace check - #108471
BartekObudzinski wants to merge 3 commits into
Conversation
Codecov Report✅ Changes either increased or maintained existing code coverage, great job!
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a896966ac7
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
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".
| } | ||
|
|
||
| // eslint-disable-next-line import/prefer-default-export -- PolicyUtils/index.ts re-exports its modules with `export *`, which skips default exports. | ||
| export {getPolicyList}; |
There was a problem hiding this comment.
Rename the single-export module to getPolicyList.ts
CONSISTENCY-9 in .claude/skills/app-coding-standards/rules/consistency-9-file-naming.md requires newly added source files to be named after their primary export. This module exports only getPolicyList, so policyList.ts violates that convention and does not qualify for the multi-export utilities exception. Rename it to getPolicyList.ts and update the barrel re-export so the helper is discoverable under its exported name.
AGENTS.md reference: AGENTS.md:L7-L9
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Renamed to getPolicyList.ts.
|
The speedup depends on Two ways it can stop being true:
it('reuses the list for the collection useOnyx returns', async () => {
// Given workspaces stored in Onyx and read with useOnyx, the way the Spend bulk actions read them
await Onyx.multiSet({
[`${ONYXKEYS.COLLECTION.POLICY}1`]: createRandomPolicy(1),
[`${ONYXKEYS.COLLECTION.POLICY}2`]: createRandomPolicy(2),
});
await waitForBatchedUpdates();
const {result} = renderHook(() => useOnyx(ONYXKEYS.COLLECTION.POLICY));
const policies = result.current[0];
// When the workspaces are listed twice, like once per selected report
const firstList = getPolicyList(policies);
const secondList = getPolicyList(policies);
// Then the same array comes back, which only holds while Onyx keeps freezing collection snapshots
expect(Object.isFrozen(policies)).toBe(true);
expect(secondList).toBe(firstList);
}); |
JmillsExpensify
left a comment
There was a problem hiding this comment.
No product review required.
…er to getPolicyList.ts
|
@DylanDylann Good call. Added a test that reads the policies through |
Reviewer Checklist
Screenshots/VideosScreen.Recording.2026-12-02.at.15.16.03.mov |
DylanDylann
left a comment
There was a problem hiding this comment.
All good. @BartekObudzinski Can you complete the checklist?
Explanation of Change
When reports are selected in Spend,
useSearchBulkActionschecks every selected report to decide whether to offer "Change workspace". Both checks behind it,isChangeWorkspaceActionandcanChangeWorkspaceOfSearchReport, loop over the policy collection withObject.values(policies). That builds a new array of every workspace for each selected report, even when the loop stops after the first two workspaces. On an account with about 6,000 workspaces, selecting a page of reports copies the whole collection once per report.A new
getPolicyListhelper inPolicyUtilslists the workspaces once per policy collection snapshot and reuses that list. Onyx freezes each collection snapshot and gives subscribers a new object when a workspace changes, so the list is only cached for frozen collections and a changed workspace always gets a fresh list. The two checks loop over that list, and their logic and results are unchanged.Measured on a production build with a large account's data (about 6,000 workspaces), selecting all 50 reports on the Spend Reports page, CPU throttled 4x, median of 3 runs:
canChangeWorkspaceOfSearchReportuseSearchBulkActionsThe gain is largest when the selected reports can't change workspace.
useSearchBulkActionsstops at the first report that can change workspace, whileSearchChangeWorkspacePagechecks every selected report.Fixed Issues
$ #108489
PROPOSAL:
Tests
Offline tests
"Change workspace" is only offered online, so this change does not alter offline behavior. Go offline in Spend with reports selected and verify that "Change workspace" is not offered, the same as on
main.QA Steps
Same as tests.
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
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
🤖 Generated with Claude Code