Repository navigation
Find expense actions in one pass in getAllNonDeletedTransactions
#107294
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
Merged
roryabraham
merged 3 commits into
Expensify:main
from
twilight2294:report-open-iou-action-index
Nov 19, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| /** | ||
| * Measures getAllNonDeletedTransactions as an expense report grows. Opening a report runs it in several hooks, | ||
| * so its cost per call is paid many times on every open. | ||
| */ | ||
| import {getAllNonDeletedTransactions} from '@libs/MoneyRequestReportUtils'; | ||
|
|
||
| import CONST from '@src/CONST'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import type {ReportAction, Transaction} from '@src/types/onyx'; | ||
|
|
||
| import type {OnyxCollection} from 'react-native-onyx'; | ||
|
|
||
| import {measureFunction} from 'reassure'; | ||
|
|
||
| import createRandomReportAction from '../utils/collections/reportActions'; | ||
| import createRandomTransaction from '../utils/collections/transaction'; | ||
|
|
||
| const REPORT_ID = '1'; | ||
| const EXPENSE_COUNTS = [50, 100, 250, 500, 1000]; | ||
|
|
||
| /** One expense action and one comment per expense, like a report people have talked about. */ | ||
| function buildReport(expenseCount: number): {transactions: OnyxCollection<Transaction>; reportActions: ReportAction[]} { | ||
| const transactions: OnyxCollection<Transaction> = {}; | ||
| const reportActions: ReportAction[] = []; | ||
| for (let index = 1; index <= expenseCount; index++) { | ||
| const transactionID = String(index); | ||
| transactions[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`] = { | ||
| ...createRandomTransaction(index), | ||
| transactionID, | ||
| reportID: REPORT_ID, | ||
| pendingAction: null, | ||
| errorFields: undefined, | ||
| }; | ||
| reportActions.push({ | ||
| ...createRandomReportAction(index), | ||
| reportActionID: `iou${index}`, | ||
| actionName: CONST.REPORT.ACTIONS.TYPE.IOU, | ||
| pendingAction: null, | ||
| message: [{type: 'COMMENT', html: '$1.00 expense', text: '$1.00 expense'}], | ||
| // eslint-disable-next-line @typescript-eslint/no-deprecated -- getOriginalMessage reads the expense's IOUTransactionID from here | ||
| originalMessage: {IOUTransactionID: transactionID, IOUReportID: REPORT_ID, type: CONST.IOU.REPORT_ACTION_TYPE.CREATE, amount: 100, currency: CONST.CURRENCY.USD}, | ||
| }); | ||
| reportActions.push({ | ||
| ...createRandomReportAction(expenseCount + index), | ||
| reportActionID: `comment${index}`, | ||
| actionName: CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT, | ||
| pendingAction: null, | ||
| message: [{type: 'COMMENT', html: 'comment', text: 'comment'}], | ||
| }); | ||
| } | ||
| return {transactions, reportActions}; | ||
| } | ||
|
|
||
| describe('getAllNonDeletedTransactions', () => { | ||
| for (const expenseCount of EXPENSE_COUNTS) { | ||
| test(`[MoneyRequestReportUtils] getAllNonDeletedTransactions on a report with ${expenseCount} expenses`, async () => { | ||
| // Given a report where every expense has its action and a comment | ||
| const {transactions, reportActions} = buildReport(expenseCount); | ||
| expect(getAllNonDeletedTransactions(transactions, reportActions, false, true)).toHaveLength(expenseCount); | ||
|
|
||
| // When the report's expenses are read, like on every update while the report opens | ||
| await measureFunction(() => getAllNonDeletedTransactions(transactions, reportActions, false, true)); | ||
| // Then reassure measures one call, which should grow only linearly with the expenses | ||
| }); | ||
| } | ||
| }); |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: Do we need this check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes,
getIOUActionForTransactionIDreturns the first match, so this keeps the same one. Without it the last action wins, and the new test with a deleted and a live action fails.