From a702e2db7b6db5f21075d5860de0f97eee5c1915 Mon Sep 17 00:00:00 2001 From: Shubham Agrawal Date: Fri, 1 Aug 2025 11:51:50 +0530 Subject: [PATCH] Removed Onyx.connect from NVP Migration --- package.json | 2 +- src/ONYXKEYS.ts | 2 - src/libs/migrateOnyx.ts | 2 - src/libs/migrations/NVPMigration.ts | 79 ----------------------------- 4 files changed, 1 insertion(+), 84 deletions(-) delete mode 100644 src/libs/migrations/NVPMigration.ts diff --git a/package.json b/package.json index 726f2e510739..50cc3a255de3 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=331 --cache --cache-location=node_modules/.cache/eslint", + "lint": "NODE_OPTIONS=--max_old_space_size=8192 eslint . --max-warnings=329 --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/ONYXKEYS.ts b/src/ONYXKEYS.ts index f5bf0571c786..da5fdb23fd4b 100755 --- a/src/ONYXKEYS.ts +++ b/src/ONYXKEYS.ts @@ -576,7 +576,6 @@ const ONYXKEYS = { // should not be included as part of the policy object. The policy // object should mirror the data as it's stored in the database. POLICY_HAS_CONNECTIONS_DATA_BEEN_FETCHED: 'policyHasConnectionsDataBeenFetched_', - OLD_POLICY_RECENTLY_USED_TAGS: 'policyRecentlyUsedTags_', POLICY_CONNECTION_SYNC_PROGRESS: 'policyConnectionSyncProgress_', WORKSPACE_INVITE_MEMBERS_DRAFT: 'workspaceInviteMembersDraft_', WORKSPACE_INVITE_MESSAGE_DRAFT: 'workspaceInviteMessageDraft_', @@ -1006,7 +1005,6 @@ type OnyxCollectionValuesMapping = { [ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS]: OnyxTypes.TransactionViolations; [ONYXKEYS.COLLECTION.SPLIT_TRANSACTION_DRAFT]: OnyxTypes.Transaction; [ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_TAGS]: OnyxTypes.RecentlyUsedTags; - [ONYXKEYS.COLLECTION.OLD_POLICY_RECENTLY_USED_TAGS]: OnyxTypes.RecentlyUsedTags; [ONYXKEYS.COLLECTION.SELECTED_TAB]: OnyxTypes.SelectedTabRequest; [ONYXKEYS.COLLECTION.PRIVATE_NOTES_DRAFT]: string; [ONYXKEYS.COLLECTION.NVP_EXPENSIFY_REPORT_PDF_FILENAME]: string; diff --git a/src/libs/migrateOnyx.ts b/src/libs/migrateOnyx.ts index f0a9ec9db977..1295a43d3c34 100644 --- a/src/libs/migrateOnyx.ts +++ b/src/libs/migrateOnyx.ts @@ -1,7 +1,6 @@ import Log from './Log'; import KeyReportActionsDraftByReportActionID from './migrations/KeyReportActionsDraftByReportActionID'; import MoveIsOptimisticReportToMetadata from './migrations/MoveIsOptimisticReportToMetadata'; -import NVPMigration from './migrations/NVPMigration'; import PendingMembersToMetadata from './migrations/PendingMembersToMetadata'; import PronounsMigration from './migrations/PronounsMigration'; import RemoveEmptyReportActionsDrafts from './migrations/RemoveEmptyReportActionsDrafts'; @@ -21,7 +20,6 @@ export default function () { KeyReportActionsDraftByReportActionID, TransactionBackupsToCollection, RemoveEmptyReportActionsDrafts, - NVPMigration, PronounsMigration, MoveIsOptimisticReportToMetadata, PendingMembersToMetadata, diff --git a/src/libs/migrations/NVPMigration.ts b/src/libs/migrations/NVPMigration.ts deleted file mode 100644 index 6a4f61f30407..000000000000 --- a/src/libs/migrations/NVPMigration.ts +++ /dev/null @@ -1,79 +0,0 @@ -import after from 'lodash/after'; -import Onyx from 'react-native-onyx'; -import type {KeyValueMapping, OnyxEntry} from 'react-native-onyx'; -import type {Account} from 'src/types/onyx'; -import ONYXKEYS from '@src/ONYXKEYS'; -import type {OnyxKey} from '@src/ONYXKEYS'; - -// These are the oldKeyName: newKeyName of the NVPs we can migrate without any processing -const migrations = { - // eslint-disable-next-line @typescript-eslint/naming-convention - nvp_lastPaymentMethod: ONYXKEYS.NVP_LAST_PAYMENT_METHOD, - preferredLocale: ONYXKEYS.NVP_PREFERRED_LOCALE, - preferredEmojiSkinTone: ONYXKEYS.PREFERRED_EMOJI_SKIN_TONE, - frequentlyUsedEmojis: ONYXKEYS.FREQUENTLY_USED_EMOJIS, - private_blockedFromConcierge: ONYXKEYS.NVP_BLOCKED_FROM_CONCIERGE, - private_pushNotificationID: ONYXKEYS.NVP_PRIVATE_PUSH_NOTIFICATION_ID, - tryFocusMode: ONYXKEYS.NVP_TRY_FOCUS_MODE, - introSelected: ONYXKEYS.NVP_INTRO_SELECTED, - preferredTheme: ONYXKEYS.PREFERRED_THEME, -}; - -// This migration changes the keys of all the NVP related keys so that they are standardized -export default function () { - return new Promise((resolve) => { - // Resolve the migration when all the keys have been migrated. The number of keys is the size of the `migrations` object in addition to the ACCOUNT and OLD_POLICY_RECENTLY_USED_TAGS keys (which is why there is a +2). - const resolveWhenDone = after(Object.entries(migrations).length + 2, () => resolve()); - - for (const [oldKey, newKey] of Object.entries(migrations)) { - const connection = Onyx.connect({ - key: oldKey as OnyxKey, - callback: (value) => { - Onyx.disconnect(connection); - if (value === undefined) { - resolveWhenDone(); - return; - } - Onyx.multiSet({ - [newKey]: value, - [oldKey]: null, - } as KeyValueMapping).then(resolveWhenDone); - }, - }); - } - const accountConnection = Onyx.connect({ - key: ONYXKEYS.ACCOUNT, - callback: (value: OnyxEntry) => { - Onyx.disconnect(accountConnection); - if (!value?.activePolicyID) { - resolveWhenDone(); - return; - } - const activePolicyID = value.activePolicyID; - const newValue = {...value}; - delete newValue.activePolicyID; - Onyx.multiSet({ - [ONYXKEYS.NVP_ACTIVE_POLICY_ID]: activePolicyID, - [ONYXKEYS.ACCOUNT]: newValue, - }).then(resolveWhenDone); - }, - }); - const recentlyUsedTagsConnection = Onyx.connect({ - key: ONYXKEYS.COLLECTION.OLD_POLICY_RECENTLY_USED_TAGS, - waitForCollectionCallback: true, - callback: (value) => { - Onyx.disconnect(recentlyUsedTagsConnection); - if (!value) { - resolveWhenDone(); - return; - } - const newValue = {} as Record; - for (const key of Object.keys(value)) { - newValue[`nvp_${key}`] = value[key]; - newValue[key] = null; - } - Onyx.multiSet(newValue as KeyValueMapping).then(resolveWhenDone); - }, - }); - }); -}