Skip to content

Commit 008b0dd

Browse files
committed
Remove composite scenario from SidebarUtils perf test
1 parent 9820901 commit 008b0dd

1 file changed

Lines changed: 48 additions & 110 deletions

File tree

tests/perf-test/SidebarUtils.perf-test.ts

Lines changed: 48 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
import {rand} from '@ngneat/falso';
2-
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
2+
import type {OnyxCollection} from 'react-native-onyx';
33
import Onyx from 'react-native-onyx';
44
import {measureFunction} from 'reassure';
55
import {getMovedReportID} from '@libs/ModifiedExpenseMessage';
66
import {getLastMessageTextForReport} from '@libs/OptionsListUtils';
77
import {
8-
getOriginalMessage,
98
getSortedReportActions,
109
getSortedReportActionsForDisplay,
11-
isInviteOrRemovedAction,
1210
shouldReportActionBeVisibleAsLastAction,
1311
} from '@libs/ReportActionsUtils';
14-
import {canUserPerformWriteAction} from '@libs/ReportUtils';
1512
import SidebarUtils from '@libs/SidebarUtils';
1613
import CONST from '@src/CONST';
1714
import ONYXKEYS from '@src/ONYXKEYS';
@@ -75,12 +72,12 @@ const createLHNReportsWithActions = (count: number) => {
7572
const reports: OnyxCollection<Report> = {};
7673
const reportActions: OnyxCollection<ReportActions> = {};
7774
const reportNameValuePairs: OnyxCollection<ReportNameValuePairs> = {};
78-
const policies: OnyxCollection<Policy> = {};
75+
const lhnPoliciesMap: OnyxCollection<Policy> = {};
7976
const personalDetailsWithActions: OnyxCollection<PersonalDetails> = {};
8077
const reportMetadata: OnyxCollection<ReportMetadata> = {};
8178

8279
const basePolicy = createRandomPolicy(1);
83-
policies[`${ONYXKEYS.COLLECTION.POLICY}${basePolicy.id}`] = basePolicy;
80+
lhnPoliciesMap[`${ONYXKEYS.COLLECTION.POLICY}${basePolicy.id}`] = basePolicy;
8481

8582
for (let i = 1; i <= count; i++) {
8683
const reportID = String(i);
@@ -118,7 +115,7 @@ const createLHNReportsWithActions = (count: number) => {
118115
reports,
119116
reportActions,
120117
reportNameValuePairs,
121-
policies,
118+
policies: lhnPoliciesMap,
122119
personalDetailsWithActions,
123120
reportMetadata,
124121
};
@@ -252,120 +249,61 @@ describe('SidebarUtils', () => {
252249
test('[SidebarUtils LHN] getLastMessageTextForReport across all reports', async () => {
253250
await waitForBatchedUpdates();
254251

255-
await measureFunction(() => {
256-
for (const reportKey of Object.keys(lhnReports)) {
252+
const inputs = Object.keys(lhnReports)
253+
.map((reportKey) => {
257254
const reportID = reportKey.replace(ONYXKEYS.COLLECTION.REPORT, '');
258255
const report = lhnReports[reportKey];
259256
const nvp = lhnReportNameValuePairs[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${reportID}`];
260257
const actions = lhnReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`];
261258
const isReportArchived = !!nvp?.private_isArchived;
262259

263-
if (report && actions) {
264-
const lastActorAccountID = report.lastActorAccountID;
265-
let lastActorDetails: Partial<PersonalDetails> | null = null;
266-
if (lastActorAccountID && lhnPersonalDetails[lastActorAccountID]) {
267-
lastActorDetails = lhnPersonalDetails[lastActorAccountID];
268-
}
260+
if (!report || !actions) {
261+
return null;
262+
}
269263

270-
const sortedActions = getSortedReportActions(Object.values(actions), true);
271-
const lastReportAction = sortedActions.at(0);
272-
273-
const movedFromReportID = lastReportAction ? getMovedReportID(lastReportAction, CONST.REPORT.MOVE_TYPE.FROM) : undefined;
274-
const movedToReportID = lastReportAction ? getMovedReportID(lastReportAction, CONST.REPORT.MOVE_TYPE.TO) : undefined;
275-
const movedFromReport = movedFromReportID ? lhnReports[`${ONYXKEYS.COLLECTION.REPORT}${movedFromReportID}`] : undefined;
276-
const movedToReport = movedToReportID ? lhnReports[`${ONYXKEYS.COLLECTION.REPORT}${movedToReportID}`] : undefined;
277-
278-
const itemPolicy = lhnPolicies[`${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`];
279-
const itemReportMetadata = lhnReportMetadata[`${ONYXKEYS.COLLECTION.REPORT_METADATA}${reportID}`];
280-
281-
getLastMessageTextForReport({
282-
translate: () => '',
283-
report,
284-
lastActorDetails,
285-
movedFromReport,
286-
movedToReport,
287-
policy: itemPolicy,
288-
isReportArchived,
289-
policyForMovingExpensesID: undefined,
290-
reportMetadata: itemReportMetadata,
291-
currentUserAccountID: 0,
292-
});
264+
const lastActorAccountID = report.lastActorAccountID;
265+
let lastActorDetails: Partial<PersonalDetails> | null = null;
266+
if (lastActorAccountID && lhnPersonalDetails[lastActorAccountID]) {
267+
lastActorDetails = lhnPersonalDetails[lastActorAccountID];
293268
}
294-
}
295-
});
296-
});
297269

298-
test('[SidebarUtils LHN] composite renderItem-style simulation for all reports', async () => {
299-
await waitForBatchedUpdates();
270+
const sortedActions = getSortedReportActions(Object.values(actions), true);
271+
const lastReportAction = sortedActions.at(0);
272+
273+
const movedFromReportID = lastReportAction ? getMovedReportID(lastReportAction, CONST.REPORT.MOVE_TYPE.FROM) : undefined;
274+
const movedToReportID = lastReportAction ? getMovedReportID(lastReportAction, CONST.REPORT.MOVE_TYPE.TO) : undefined;
275+
const movedFromReport = movedFromReportID ? lhnReports[`${ONYXKEYS.COLLECTION.REPORT}${movedFromReportID}`] : undefined;
276+
const movedToReport = movedToReportID ? lhnReports[`${ONYXKEYS.COLLECTION.REPORT}${movedToReportID}`] : undefined;
277+
278+
const itemPolicy = lhnPolicies[`${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`];
279+
const itemReportMetadata = lhnReportMetadata[`${ONYXKEYS.COLLECTION.REPORT_METADATA}${reportID}`];
280+
281+
return {
282+
report,
283+
lastActorDetails,
284+
movedFromReport,
285+
movedToReport,
286+
itemPolicy,
287+
isReportArchived,
288+
itemReportMetadata,
289+
};
290+
})
291+
.filter((value): value is NonNullable<typeof value> => value !== null);
300292

301293
await measureFunction(() => {
302-
for (const reportKey of Object.keys(lhnReports)) {
303-
const reportID = reportKey.replace(ONYXKEYS.COLLECTION.REPORT, '');
304-
const item = lhnReports[reportKey];
305-
const itemReportActions = lhnReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`];
306-
const itemReportNameValuePairs = lhnReportNameValuePairs[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${reportID}`];
307-
const isReportArchived = !!itemReportNameValuePairs?.private_isArchived;
308-
309-
if (itemReportActions && item) {
310-
const canUserPerformWrite = canUserPerformWriteAction(item, isReportArchived);
311-
const sortedReportActions = getSortedReportActionsForDisplay(itemReportActions, canUserPerformWrite);
312-
const lastReportAction = sortedReportActions.at(0);
313-
314-
let lastActorDetails: Partial<PersonalDetails> | null = null;
315-
if (item.lastActorAccountID && lhnPersonalDetails[item.lastActorAccountID]) {
316-
lastActorDetails = lhnPersonalDetails[item.lastActorAccountID] ?? null;
317-
} else if (lastReportAction) {
318-
const lastActorDisplayName = lastReportAction?.person?.[0]?.text;
319-
lastActorDetails = lastActorDisplayName
320-
? {
321-
displayName: lastActorDisplayName,
322-
accountID: item.lastActorAccountID,
323-
}
324-
: null;
325-
}
326-
327-
const movedFromReportID = lastReportAction ? getMovedReportID(lastReportAction, CONST.REPORT.MOVE_TYPE.FROM) : undefined;
328-
const movedToReportID = lastReportAction ? getMovedReportID(lastReportAction, CONST.REPORT.MOVE_TYPE.TO) : undefined;
329-
const movedFromReport = movedFromReportID ? lhnReports[`${ONYXKEYS.COLLECTION.REPORT}${movedFromReportID}`] : undefined;
330-
const movedToReport = movedToReportID ? lhnReports[`${ONYXKEYS.COLLECTION.REPORT}${movedToReportID}`] : undefined;
331-
332-
const itemPolicy = lhnPolicies[`${ONYXKEYS.COLLECTION.POLICY}${item.policyID}`];
333-
const itemReportMetadata = lhnReportMetadata[`${ONYXKEYS.COLLECTION.REPORT_METADATA}${reportID}`];
334-
335-
const lastMessageTextFromReport = getLastMessageTextForReport({
336-
translate: () => '',
337-
report: item,
338-
lastActorDetails,
339-
movedFromReport,
340-
movedToReport,
341-
policy: itemPolicy,
342-
isReportArchived,
343-
policyForMovingExpensesID: undefined,
344-
reportMetadata: itemReportMetadata,
345-
currentUserAccountID: 0,
346-
});
347-
348-
const canUserPerformWriteActionForLastAction = canUserPerformWriteAction(item, isReportArchived);
349-
const actionsArray = getSortedReportActions(Object.values(itemReportActions));
350-
351-
const reportActionsForDisplay = actionsArray.filter(
352-
(reportAction) =>
353-
shouldReportActionBeVisibleAsLastAction(reportAction, canUserPerformWriteActionForLastAction) &&
354-
reportAction.actionName !== CONST.REPORT.ACTIONS.TYPE.CREATED,
355-
);
356-
const lastAction = reportActionsForDisplay.at(-1);
357-
358-
let lastActionReport: OnyxEntry<Report> | undefined;
359-
if (lastAction && isInviteOrRemovedAction(lastAction)) {
360-
const lastActionOriginalMessage = lastAction?.actionName ? getOriginalMessage(lastAction) : null;
361-
lastActionReport = lastActionOriginalMessage?.reportID
362-
? lhnReports[`${ONYXKEYS.COLLECTION.REPORT}${lastActionOriginalMessage.reportID}`]
363-
: undefined;
364-
}
365-
366-
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
367-
[lastMessageTextFromReport, lastAction, lastActionReport];
368-
}
294+
for (const input of inputs) {
295+
getLastMessageTextForReport({
296+
translate: () => '',
297+
report: input.report,
298+
lastActorDetails: input.lastActorDetails,
299+
movedFromReport: input.movedFromReport,
300+
movedToReport: input.movedToReport,
301+
policy: input.itemPolicy,
302+
isReportArchived: input.isReportArchived,
303+
policyForMovingExpensesID: undefined,
304+
reportMetadata: input.itemReportMetadata,
305+
currentUserAccountID: 0,
306+
});
369307
}
370308
});
371309
});

0 commit comments

Comments
 (0)