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, @@ -461,7 +449,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 20728245b70c..fe16c8d1a2e5 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -2910,10 +2910,6 @@ function getCardIssuedMessage({ } } -function getReportActionsLength() { - return Object.keys(allReportActions ?? {}).length; -} - function getReportActions(report: Report) { return allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`]; } @@ -3125,7 +3121,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,