|
1 | 1 | import {getLastClosedReportAction} from '@selectors/ReportAction'; |
2 | 2 | import Onyx from 'react-native-onyx'; |
3 | 3 | import {measureFunction} from 'reassure'; |
4 | | -import {getLastVisibleAction, getLastVisibleMessage, getMostRecentIOURequestActionID, getSortedReportActionsForDisplay} from '@libs/ReportActionsUtils'; |
| 4 | +import { |
| 5 | + getLastVisibleAction, |
| 6 | + getLastVisibleMessage, |
| 7 | + getMostRecentIOURequestActionID, |
| 8 | + getSortedReportActions, |
| 9 | + getSortedReportActionsForDisplay, |
| 10 | +} from '@libs/ReportActionsUtils'; |
5 | 11 | import CONST from '@src/CONST'; |
6 | 12 | import ONYXKEYS from '@src/ONYXKEYS'; |
7 | 13 | import type {ReportActions} from '@src/types/onyx/ReportAction'; |
@@ -35,6 +41,7 @@ const reportActions = createCollection<ReportAction>( |
35 | 41 | ); |
36 | 42 |
|
37 | 43 | const reportId = '1'; |
| 44 | +const ACTIONS_COUNT_CACHE = 100; |
38 | 45 |
|
39 | 46 | describe('ReportActionsUtils', () => { |
40 | 47 | beforeAll(() => { |
@@ -140,4 +147,33 @@ describe('ReportActionsUtils', () => { |
140 | 147 | await waitForBatchedUpdates(); |
141 | 148 | await measureFunction(() => getLastClosedReportAction(reportActions)); |
142 | 149 | }); |
| 150 | + |
| 151 | + test('[ReportActionsUtils] getSortedReportActions cache hit performance', async () => { |
| 152 | + const reportActionsForCache = createCollection<ReportAction>( |
| 153 | + (item) => `${item.reportActionID}`, |
| 154 | + (index) => createRandomReportAction(index), |
| 155 | + ACTIONS_COUNT_CACHE, |
| 156 | + ); |
| 157 | + const actionsArray = Object.values(reportActionsForCache); |
| 158 | + |
| 159 | + await measureFunction(() => getSortedReportActions(actionsArray, true), { |
| 160 | + runs: 20, |
| 161 | + warmupRuns: 5, |
| 162 | + }); |
| 163 | + }); |
| 164 | + |
| 165 | + test('[ReportActionsUtils] getSortedReportActions cache hit with different array references', async () => { |
| 166 | + const reportActionsForCache = createCollection<ReportAction>( |
| 167 | + (item) => `${item.reportActionID}`, |
| 168 | + (index) => createRandomReportAction(index), |
| 169 | + ACTIONS_COUNT_CACHE, |
| 170 | + ); |
| 171 | + const actionsArray = Object.values(reportActionsForCache); |
| 172 | + const newArrayRef = [...actionsArray]; |
| 173 | + |
| 174 | + await measureFunction(() => getSortedReportActions(newArrayRef, true), { |
| 175 | + runs: 20, |
| 176 | + warmupRuns: 5, |
| 177 | + }); |
| 178 | + }); |
143 | 179 | }); |
0 commit comments