Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -414,14 +414,14 @@ Different platforms come with varying storage capacities and Onyx has a way to g
By default, Onyx will not evict anything from storage and will presume all keys are "unsafe" to remove unless explicitly told otherwise.

**To flag a key as safe for removal:**
- Add the key to the `safeEvictionKeys` option in `Onyx.init(options)`
- Add the key to the `evictableKeys` option in `Onyx.init(options)`
- Implement `canEvict` in the Onyx config for each component subscribing to a key
- The key will only be deleted when all subscribers return `true` for `canEvict`

e.g.
```js
Onyx.init({
safeEvictionKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
evictableKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
});
```

Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
"react-native-launch-arguments": "^4.0.2",
"react-native-localize": "^2.2.6",
"react-native-modal": "^13.0.0",
"react-native-onyx": "2.0.102",
"react-native-onyx": "^2.0.104",
"react-native-pager-view": "6.5.2",
"react-native-pdf": "6.7.3",
"react-native-performance": "^5.1.0",
Expand Down
8 changes: 7 additions & 1 deletion src/setup/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ export default function () {

// Increase the cached key count so that the app works more consistently for accounts with large numbers of reports
maxCachedKeysCount: 50000,
safeEvictionKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS, ONYXKEYS.COLLECTION.SNAPSHOT],
evictableKeys: [
ONYXKEYS.COLLECTION.REPORT_ACTIONS,
ONYXKEYS.COLLECTION.SNAPSHOT,
ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS,
ONYXKEYS.COLLECTION.REPORT_ACTIONS_PAGES,
ONYXKEYS.COLLECTION.REPORT_ACTIONS_REACTIONS,
],
initialKeyStates: {
// Clear any loading and error messages so they do not appear on app startup
[ONYXKEYS.SESSION]: {loading: false},
Expand Down
2 changes: 1 addition & 1 deletion tests/perf-test/ModifiedExpenseMessage.perf-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import waitForBatchedUpdates from '../utils/waitForBatchedUpdates';
beforeAll(() =>
Onyx.init({
keys: ONYXKEYS,
safeEvictionKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
evictableKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
}),
);

Expand Down
2 changes: 1 addition & 1 deletion tests/perf-test/ReportActionCompose.perf-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jest.mock('@components/ConfirmedRoute.tsx');
beforeAll(() =>
Onyx.init({
keys: ONYXKEYS,
safeEvictionKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
evictableKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
}),
);

Expand Down
2 changes: 1 addition & 1 deletion tests/perf-test/ReportActionsList.perf-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jest.mock('@src/components/ConfirmedRoute.tsx');
beforeAll(() =>
Onyx.init({
keys: ONYXKEYS,
safeEvictionKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
evictableKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
}),
);

Expand Down
2 changes: 1 addition & 1 deletion tests/perf-test/ReportActionsUtils.perf-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('ReportActionsUtils', () => {
beforeAll(() => {
Onyx.init({
keys: ONYXKEYS,
safeEvictionKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
evictableKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
});

Onyx.multiSet({
Expand Down
52 changes: 33 additions & 19 deletions tests/perf-test/ReportUtils.perf-test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
import Onyx from 'react-native-onyx';
import {measureFunction} from 'reassure';
import * as ReportUtils from '@libs/ReportUtils';
import {
canDeleteReportAction,
canShowReportRecipientLocalTime,
findLastAccessedReport,
getDisplayNamesWithTooltips,
getIcons,
getIconsForParticipants,
getIOUReportActionDisplayMessage,
getReportName,
getReportPreviewMessage,
getReportRecipientAccountIDs,
getTransactionDetails,
getWorkspaceChats,
getWorkspaceIcon,
shouldReportBeInOptionList,
temporary_getMoneyRequestOptions,
} from '@libs/ReportUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {PersonalDetails, Policy, Report, ReportAction} from '@src/types/onyx';
Expand Down Expand Up @@ -40,7 +56,7 @@ describe('ReportUtils', () => {
beforeAll(() => {
Onyx.init({
keys: ONYXKEYS,
safeEvictionKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
evictableKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
});
});

Expand All @@ -67,30 +83,30 @@ describe('ReportUtils', () => {
});

await waitForBatchedUpdates();
await measureFunction(() => ReportUtils.findLastAccessedReport(ignoreDomainRooms, openOnAdminRoom));
await measureFunction(() => findLastAccessedReport(ignoreDomainRooms, openOnAdminRoom));
});

test('[ReportUtils] canDeleteReportAction on 1k reports and policies', async () => {
const reportID = '1';
const reportAction = {...createRandomReportAction(1), actionName: CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT} as unknown as ReportAction;

await waitForBatchedUpdates();
await measureFunction(() => ReportUtils.canDeleteReportAction(reportAction, reportID));
await measureFunction(() => canDeleteReportAction(reportAction, reportID));
});

test('[ReportUtils] getReportRecipientAccountID on 1k participants', async () => {
const report = {...createRandomReport(1), participantAccountIDs};
const currentLoginAccountID = 1;

await waitForBatchedUpdates();
await measureFunction(() => ReportUtils.getReportRecipientAccountIDs(report, currentLoginAccountID));
await measureFunction(() => getReportRecipientAccountIDs(report, currentLoginAccountID));
});

test('[ReportUtils] getIconsForParticipants on 1k participants', async () => {
const participants = Array.from({length: 1000}, (v, i) => i + 1);

await waitForBatchedUpdates();
await measureFunction(() => ReportUtils.getIconsForParticipants(participants, personalDetails));
await measureFunction(() => getIconsForParticipants(participants, personalDetails));
});

test('[ReportUtils] getIcons on 1k participants', async () => {
Expand All @@ -101,15 +117,15 @@ describe('ReportUtils', () => {
const defaultIconId = -1;

await waitForBatchedUpdates();
await measureFunction(() => ReportUtils.getIcons(report, personalDetails, defaultIcon, defaultName, defaultIconId, policy));
await measureFunction(() => getIcons(report, personalDetails, defaultIcon, defaultName, defaultIconId, policy));
});

test('[ReportUtils] getDisplayNamesWithTooltips 1k participants', async () => {
const isMultipleParticipantReport = true;
const shouldFallbackToHidden = true;

await waitForBatchedUpdates();
await measureFunction(() => ReportUtils.getDisplayNamesWithTooltips(personalDetails, isMultipleParticipantReport, shouldFallbackToHidden));
await measureFunction(() => getDisplayNamesWithTooltips(personalDetails, isMultipleParticipantReport, shouldFallbackToHidden));
});

test('[ReportUtils] getReportPreviewMessage on 1k policies', async () => {
Expand All @@ -120,23 +136,23 @@ describe('ReportUtils', () => {
const isPreviewMessageForParentChatReport = true;

await waitForBatchedUpdates();
await measureFunction(() => ReportUtils.getReportPreviewMessage(report, reportAction, shouldConsiderReceiptBeingScanned, isPreviewMessageForParentChatReport, policy));
await measureFunction(() => getReportPreviewMessage(report, reportAction, shouldConsiderReceiptBeingScanned, isPreviewMessageForParentChatReport, policy));
});

test('[ReportUtils] getReportName on 1k participants', async () => {
const report = {...createRandomReport(1), chatType: undefined, participantAccountIDs};
const policy = createRandomPolicy(1);

await waitForBatchedUpdates();
await measureFunction(() => ReportUtils.getReportName(report, policy));
await measureFunction(() => getReportName(report, policy));
});

test('[ReportUtils] canShowReportRecipientLocalTime on 1k participants', async () => {
const report = {...createRandomReport(1), participantAccountIDs};
const accountID = 1;

await waitForBatchedUpdates();
await measureFunction(() => ReportUtils.canShowReportRecipientLocalTime(personalDetails, report, accountID));
await measureFunction(() => canShowReportRecipientLocalTime(personalDetails, report, accountID));
});

test('[ReportUtils] shouldReportBeInOptionList on 1k participant', async () => {
Expand All @@ -147,17 +163,15 @@ describe('ReportUtils', () => {
const policies = getMockedPolicies();

await waitForBatchedUpdates();
await measureFunction(() =>
ReportUtils.shouldReportBeInOptionList({report, currentReportId, isInFocusMode, betas, policies, doesReportHaveViolations: false, excludeEmptyChats: false}),
);
await measureFunction(() => shouldReportBeInOptionList({report, currentReportId, isInFocusMode, betas, policies, doesReportHaveViolations: false, excludeEmptyChats: false}));
});

test('[ReportUtils] getWorkspaceIcon on 1k policies', async () => {
const report = createRandomReport(1);
const policy = createRandomPolicy(1);

await waitForBatchedUpdates();
await measureFunction(() => ReportUtils.getWorkspaceIcon(report, policy));
await measureFunction(() => getWorkspaceIcon(report, policy));
});

test('[ReportUtils] getMoneyRequestOptions on 1k participants', async () => {
Expand All @@ -166,22 +180,22 @@ describe('ReportUtils', () => {
const reportParticipants = Array.from({length: 1000}, (v, i) => i + 1);

await waitForBatchedUpdates();
await measureFunction(() => ReportUtils.temporary_getMoneyRequestOptions(report, policy, reportParticipants));
await measureFunction(() => temporary_getMoneyRequestOptions(report, policy, reportParticipants));
});

test('[ReportUtils] getWorkspaceChat on 1k policies', async () => {
const policyID = '1';
const accountsID = Array.from({length: 20}, (v, i) => i + 1);

await waitForBatchedUpdates();
await measureFunction(() => ReportUtils.getWorkspaceChats(policyID, accountsID));
await measureFunction(() => getWorkspaceChats(policyID, accountsID));
});

test('[ReportUtils] getTransactionDetails on 1k reports', async () => {
const transaction = createRandomTransaction(1);

await waitForBatchedUpdates();
await measureFunction(() => ReportUtils.getTransactionDetails(transaction, 'yyyy-MM-dd'));
await measureFunction(() => getTransactionDetails(transaction, 'yyyy-MM-dd'));
});

test('[ReportUtils] getIOUReportActionDisplayMessage on 1k policies', async () => {
Expand All @@ -200,6 +214,6 @@ describe('ReportUtils', () => {
};

await waitForBatchedUpdates();
await measureFunction(() => ReportUtils.getIOUReportActionDisplayMessage(reportAction));
await measureFunction(() => getIOUReportActionDisplayMessage(reportAction));
});
});
2 changes: 1 addition & 1 deletion tests/perf-test/SearchRouter.perf-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const mockedOptions = createOptionList(mockedPersonalDetails, mockedReports);
beforeAll(() =>
Onyx.init({
keys: ONYXKEYS,
safeEvictionKeys: [ONYXKEYS.COLLECTION.REPORT],
evictableKeys: [ONYXKEYS.COLLECTION.REPORT],
}),
);

Expand Down
2 changes: 1 addition & 1 deletion tests/perf-test/SidebarLinks.perf-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('SidebarLinks', () => {
beforeAll(() => {
Onyx.init({
keys: ONYXKEYS,
safeEvictionKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
evictableKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
});
});

Expand Down
2 changes: 1 addition & 1 deletion tests/perf-test/SidebarUtils.perf-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('SidebarUtils', () => {
beforeAll(() => {
Onyx.init({
keys: ONYXKEYS,
safeEvictionKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
evictableKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
});

Onyx.multiSet({
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/DebugReportActionsTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('DebugReportActions', () => {
beforeAll(() => {
Onyx.init({
keys: ONYXKEYS,
safeEvictionKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
evictableKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
});
});

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/LHNItemsPresence.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ describe('SidebarLinksData', () => {
beforeAll(() => {
Onyx.init({
keys: ONYXKEYS,
safeEvictionKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
evictableKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
});
});

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/ReportDetailsPageTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('ReportDetailsPage', () => {
beforeAll(() => {
Onyx.init({
keys: ONYXKEYS,
safeEvictionKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
evictableKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
});
});

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/PersistedRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const request: Request = {
beforeAll(() =>
Onyx.init({
keys: ONYXKEYS,
safeEvictionKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
evictableKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
}),
);

Expand Down
5 changes: 3 additions & 2 deletions tests/unit/ReportActionItemSingleTest.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {screen, waitFor} from '@testing-library/react-native';
import Onyx from 'react-native-onyx';
import CONST from '@src/CONST';
import type {PersonalDetailsList} from '@src/types/onyx';
import {toCollectionDataSet} from '@src/types/utils/CollectionDataSet';
import * as LHNTestUtils from '../utils/LHNTestUtils';
Expand All @@ -22,7 +23,7 @@ describe('ReportActionItemSingle', () => {
beforeAll(() =>
Onyx.init({
keys: ONYXKEYS,
safeEvictionKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
evictableKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
}),
);

Expand All @@ -44,7 +45,7 @@ describe('ReportActionItemSingle', () => {
const fakeReport = LHNTestUtils.getFakeReportWithPolicy([1, 2]);
const fakeReportAction = LHNTestUtils.getFakeAdvancedReportAction();
const fakePolicy = LHNTestUtils.getFakePolicy(fakeReport.policyID);
const faceAccountId = fakeReportAction.actorAccountID ?? -1;
const faceAccountId = fakeReportAction.actorAccountID ?? CONST.DEFAULT_NUMBER_ID;
const fakePersonalDetails: PersonalDetailsList = {
[faceAccountId]: {
accountID: faceAccountId,
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/ReportActionsUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('ReportActionsUtils', () => {
beforeAll(() =>
Onyx.init({
keys: ONYXKEYS,
safeEvictionKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
evictableKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
}),
);

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/SidebarFilterTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ xdescribe('Sidebar', () => {
beforeAll(() =>
Onyx.init({
keys: ONYXKEYS,
safeEvictionKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
evictableKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
}),
);

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/SidebarOrderTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('Sidebar', () => {
beforeAll(() =>
Onyx.init({
keys: ONYXKEYS,
safeEvictionKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
evictableKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
}),
);

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/SidebarTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('Sidebar', () => {
beforeAll(() =>
Onyx.init({
keys: ONYXKEYS,
safeEvictionKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
evictableKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
}),
);

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/SidebarUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('SidebarUtils', () => {
beforeAll(() =>
Onyx.init({
keys: ONYXKEYS,
safeEvictionKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
evictableKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
}),
);

Expand Down