From 1090c00c294b12d1f0e11533ff443e75d74ac8d1 Mon Sep 17 00:00:00 2001 From: Shubham Agrawal Date: Mon, 4 Aug 2025 21:57:35 +0530 Subject: [PATCH] Removed Onyx.connect from Firebase utils --- package.json | 2 +- src/libs/Firebase/utils.ts | 70 +++++++++++++++++++++++++------- src/libs/PersonalDetailsUtils.ts | 13 ------ src/libs/PolicyUtils.ts | 5 --- src/libs/ReportActionsUtils.ts | 5 --- src/libs/actions/Transaction.ts | 10 ----- 6 files changed, 56 insertions(+), 49 deletions(-) diff --git a/package.json b/package.json index 150698b2b0ab..ffd00838a64f 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "test:debug": "TZ=utc NODE_OPTIONS='--inspect-brk --experimental-vm-modules' jest --runInBand", "perf-test": "NODE_OPTIONS=--experimental-vm-modules npx reassure", "typecheck": "NODE_OPTIONS=--max_old_space_size=8192 tsc", - "lint": "NODE_OPTIONS=--max_old_space_size=8192 eslint . --max-warnings=319 --cache --cache-location=node_modules/.cache/eslint", + "lint": "NODE_OPTIONS=--max_old_space_size=8192 eslint . --max-warnings=317 --cache --cache-location=node_modules/.cache/eslint", "lint-changed": "NODE_OPTIONS=--max_old_space_size=8192 ./scripts/lintChanged.sh", "lint-watch": "npx eslint-watch --watch --changed", "shellcheck": "./scripts/shellCheck.sh", diff --git a/src/libs/Firebase/utils.ts b/src/libs/Firebase/utils.ts index 385fda4c817b..93b271cdb6b9 100644 --- a/src/libs/Firebase/utils.ts +++ b/src/libs/Firebase/utils.ts @@ -1,20 +1,60 @@ -import type {OnyxCollection} from 'react-native-onyx'; +// We have opted for `Onyx.connectWithoutView` here as this logic is strictly non-UI in nature. import Onyx from 'react-native-onyx'; -import {getAllTransactions, getAllTransactionViolationsLength} from '@libs/actions/Transaction'; -import * as PersonalDetailsUtils from '@libs/PersonalDetailsUtils'; -import {getActivePolicy, getAllPoliciesLength} from '@libs/PolicyUtils'; -import {getReportActionsLength} from '@libs/ReportActionsUtils'; +import {getActivePolicy} from '@libs/PolicyUtils'; import * as SessionUtils from '@libs/SessionUtils'; import ONYXKEYS from '@src/ONYXKEYS'; -import type {Report} from '@src/types/onyx'; import type {PerfAttributes} from './types'; -let allReports: OnyxCollection; -Onyx.connect({ +let reportsCount = 0; +Onyx.connectWithoutView({ key: ONYXKEYS.COLLECTION.REPORT, waitForCollectionCallback: true, callback: (value) => { - allReports = value; + reportsCount = Object.keys(value ?? {}).length; + }, +}); + +let reportActionsCount = 0; +Onyx.connectWithoutView({ + key: ONYXKEYS.COLLECTION.REPORT_ACTIONS, + waitForCollectionCallback: true, + callback: (value) => { + reportActionsCount = Object.keys(value ?? {}).length; + }, +}); + +let transactionViolationsCount = 0; +Onyx.connectWithoutView({ + key: ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, + waitForCollectionCallback: true, + callback: (value) => { + transactionViolationsCount = Object.keys(value ?? {}).length; + }, +}); + +let transactionsCount = 0; +Onyx.connectWithoutView({ + key: ONYXKEYS.COLLECTION.TRANSACTION, + waitForCollectionCallback: true, + callback: (value) => { + transactionsCount = Object.keys(value ?? {}).length; + }, +}); + +let policiesCount = 0; +Onyx.connectWithoutView({ + key: ONYXKEYS.COLLECTION.POLICY, + waitForCollectionCallback: true, + callback: (value) => { + policiesCount = Object.keys(value ?? {}).length; + }, +}); + +let personalDetailsCount = 0; +Onyx.connectWithoutView({ + key: ONYXKEYS.PERSONAL_DETAILS_LIST, + callback: (value) => { + personalDetailsCount = Object.keys(value ?? {}).length; }, }); @@ -24,12 +64,12 @@ function getAttributes(attributes?: T[]): Pick

): string | undefined }; export { - isPersonalDetailsEmpty, getDisplayNameOrDefault, getPersonalDetailsByIDs, getPersonalDetailByEmail, @@ -458,7 +446,6 @@ export { createDisplayName, extractFirstAndLastNameFromAvailableDetails, getNewAccountIDsAndLogins, - getPersonalDetailsLength, getUserNameByEmail, getShortMentionIfFound, getDefaultCountry, diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index f2175e789f58..f0dc8ba29923 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -1331,10 +1331,6 @@ function getWorkflowApprovalsUnavailable(policy: OnyxEntry) { return policy?.approvalMode === CONST.POLICY.APPROVAL_MODE.OPTIONAL || !!policy?.errorFields?.approvalMode; } -function getAllPoliciesLength() { - return Object.keys(allPolicies ?? {}).length; -} - function getActivePolicy(): OnyxEntry { // This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850 // eslint-disable-next-line deprecation/deprecation @@ -1635,7 +1631,6 @@ export { hasUnsupportedIntegration, getWorkflowApprovalsUnavailable, getNetSuiteImportCustomFieldLabel, - getAllPoliciesLength, getActivePolicy, getUserFriendlyWorkspaceType, isPolicyAccessible, diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 6c0827a35e63..3be2cc08ea1e 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -2891,10 +2891,6 @@ function getCardIssuedMessage({ } } -function getReportActionsLength() { - return Object.keys(allReportActions ?? {}).length; -} - function getReportActions(report: Report) { return allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`]; } @@ -3105,7 +3101,6 @@ export { getCardIssuedMessage, getRemovedConnectionMessage, getActionableJoinRequestPendingReportAction, - getReportActionsLength, getFilteredReportActionsForReportView, wasMessageReceivedWhileOffline, shouldShowAddMissingDetails, diff --git a/src/libs/actions/Transaction.ts b/src/libs/actions/Transaction.ts index e2eb17738373..ba86def115f4 100644 --- a/src/libs/actions/Transaction.ts +++ b/src/libs/actions/Transaction.ts @@ -584,14 +584,6 @@ function getRecentWaypoints() { return recentWaypoints; } -function getAllTransactionViolationsLength() { - return allTransactionViolations.length; -} - -function getAllTransactions() { - return Object.keys(allTransactions ?? {}).length; -} - /** * Returns a client generated 16 character hexadecimal value for the transactionID */ @@ -1069,8 +1061,6 @@ export { openDraftDistanceExpense, getRecentWaypoints, sanitizeRecentWaypoints, - getAllTransactionViolationsLength, - getAllTransactions, getLastModifiedExpense, revert, changeTransactionsReport,