From 1b8bf457e133b566f43302f7fd78c2fb866e0b6c Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Fri, 28 Jul 2023 09:26:40 -0600 Subject: [PATCH 01/13] Add action and global methods --- .../actions/MemoryOnlyKeys/MemoryOnlyKeys.js | 18 ++++++++++++++++++ .../exposeGlobalMethods/index.js | 12 ++++++++++++ .../exposeGlobalMethods/index.native.js | 6 ++++++ 3 files changed, 36 insertions(+) create mode 100644 src/libs/actions/MemoryOnlyKeys/MemoryOnlyKeys.js create mode 100644 src/libs/actions/MemoryOnlyKeys/exposeGlobalMethods/index.js create mode 100644 src/libs/actions/MemoryOnlyKeys/exposeGlobalMethods/index.native.js diff --git a/src/libs/actions/MemoryOnlyKeys/MemoryOnlyKeys.js b/src/libs/actions/MemoryOnlyKeys/MemoryOnlyKeys.js new file mode 100644 index 000000000000..940e63c44dc4 --- /dev/null +++ b/src/libs/actions/MemoryOnlyKeys/MemoryOnlyKeys.js @@ -0,0 +1,18 @@ +import * as Onyx from 'react-native-onyx'; +import ONYXKEYS from '../../../ONYXKEYS'; + +const memoryOnlyKeys = [ONYXKEYS.COLLECTION.REPORT, ONYXKEYS.COLLECTION.POLICY, ONYXKEYS.PERSONAL_DETAILS_LIST]; + +const enable = () => { + console.log('Turning on memory only keys'); + Onyx.set(ONYXKEYS.IS_USING_MEMORY_ONLY_KEYS, true); + Onyx.setMemoryOnlyKeys(memoryOnlyKeys); +}; + +const disable = () => { + console.log('Turning off memory only keys'); + Onyx.set(ONYXKEYS.IS_USING_MEMORY_ONLY_KEYS, false); + Onyx.setMemoryOnlyKeys([]); +}; + +export {disable, enable}; diff --git a/src/libs/actions/MemoryOnlyKeys/exposeGlobalMethods/index.js b/src/libs/actions/MemoryOnlyKeys/exposeGlobalMethods/index.js new file mode 100644 index 000000000000..9935efeabee8 --- /dev/null +++ b/src/libs/actions/MemoryOnlyKeys/exposeGlobalMethods/index.js @@ -0,0 +1,12 @@ +import * as MemoryOnlyKeys from '../MemoryOnlyKeys'; + +const exposeGlobalMethods = () => { + window.enableMemoryOnlyKeys = () => { + MemoryOnlyKeys.enable(); + }; + window.disableMemoryOnlyKeys = () => { + MemoryOnlyKeys.disable(); + }; +}; + +export default exposeGlobalMethods; diff --git a/src/libs/actions/MemoryOnlyKeys/exposeGlobalMethods/index.native.js b/src/libs/actions/MemoryOnlyKeys/exposeGlobalMethods/index.native.js new file mode 100644 index 000000000000..3a24512f2495 --- /dev/null +++ b/src/libs/actions/MemoryOnlyKeys/exposeGlobalMethods/index.native.js @@ -0,0 +1,6 @@ +/** + * This is a no-op because the global methods will only work for web and desktop + */ +const exposeGlobalMethods = () => {}; + +export default exposeGlobalMethods; From 20fc7e0c09a6f2107c4581917ff286472001f2eb Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Fri, 28 Jul 2023 09:33:31 -0600 Subject: [PATCH 02/13] Move and reorganize files a little --- .../index.js | 0 .../index.native.js | 0 src/setup/index.js | 14 ++------------ 3 files changed, 2 insertions(+), 12 deletions(-) rename src/libs/actions/MemoryOnlyKeys/{exposeGlobalMethods => exposeGlobalMemoryOnlyKeysMethods}/index.js (100%) rename src/libs/actions/MemoryOnlyKeys/{exposeGlobalMethods => exposeGlobalMemoryOnlyKeysMethods}/index.native.js (100%) diff --git a/src/libs/actions/MemoryOnlyKeys/exposeGlobalMethods/index.js b/src/libs/actions/MemoryOnlyKeys/exposeGlobalMemoryOnlyKeysMethods/index.js similarity index 100% rename from src/libs/actions/MemoryOnlyKeys/exposeGlobalMethods/index.js rename to src/libs/actions/MemoryOnlyKeys/exposeGlobalMemoryOnlyKeysMethods/index.js diff --git a/src/libs/actions/MemoryOnlyKeys/exposeGlobalMethods/index.native.js b/src/libs/actions/MemoryOnlyKeys/exposeGlobalMemoryOnlyKeysMethods/index.native.js similarity index 100% rename from src/libs/actions/MemoryOnlyKeys/exposeGlobalMethods/index.native.js rename to src/libs/actions/MemoryOnlyKeys/exposeGlobalMemoryOnlyKeysMethods/index.native.js diff --git a/src/setup/index.js b/src/setup/index.js index dee506302e81..e164a7c94d27 100644 --- a/src/setup/index.js +++ b/src/setup/index.js @@ -6,6 +6,7 @@ import platformSetup from './platformSetup'; import * as Metrics from '../libs/Metrics'; import * as Device from '../libs/actions/Device'; import intlPolyfill from '../libs/IntlPolyfill'; +import exposeGlobalMemoryOnlyKeysMethods from '../libs/actions/MemoryOnlyKeys/exposeGlobalMemoryOnlyKeysMethods'; export default function () { /* @@ -42,18 +43,7 @@ export default function () { }, }); - // When enabled we will skip persisting to disk any server-side downloaded objects (e.g. workspaces, chats, etc) that can hog up a user's resources. - window.enableMemoryOnlyKeys = () => { - // eslint-disable-next-line rulesdir/prefer-actions-set-data - Onyx.set(ONYXKEYS.IS_USING_MEMORY_ONLY_KEYS, true); - Onyx.setMemoryOnlyKeys([ONYXKEYS.COLLECTION.REPORT, ONYXKEYS.COLLECTION.POLICY, ONYXKEYS.PERSONAL_DETAILS_LIST]); - }; - - window.disableMemoryOnlyKeys = () => { - // eslint-disable-next-line rulesdir/prefer-actions-set-data - Onyx.set(ONYXKEYS.IS_USING_MEMORY_ONLY_KEYS, false); - Onyx.setMemoryOnlyKeys([]); - }; + exposeGlobalMemoryOnlyKeysMethods(); Device.setDeviceID(); From f09275340f40c80667419a1e93bed771e5dcd617 Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Fri, 28 Jul 2023 09:47:19 -0600 Subject: [PATCH 03/13] Check for updates in pusher response --- src/libs/actions/User.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/libs/actions/User.js b/src/libs/actions/User.js index f6652bdf8fa2..1536cb1791b2 100644 --- a/src/libs/actions/User.js +++ b/src/libs/actions/User.js @@ -18,6 +18,7 @@ import * as ReportActionsUtils from '../ReportActionsUtils'; import * as ErrorUtils from '../ErrorUtils'; import * as Session from './Session'; import * as PersonalDetails from './PersonalDetails'; +import * as MemoryOnlyKeys from './MemoryOnlyKeys/MemoryOnlyKeys'; let currentUserAccountID = ''; let currentEmail = ''; @@ -568,6 +569,19 @@ function subscribeToUserEvents() { if (!currentUserAccountID) { return; } + + // If there is an OnyxUpdate for using memory only keys, enable or disable the memory only keys according to the value. + _.each(pushJSON, ({key, val}) => { + if (key !== ONYXKEYS.IS_USING_MEMORY_ONLY_KEYS) { + return; + } + if (val) { + MemoryOnlyKeys.enable(); + } else { + MemoryOnlyKeys.disable(); + } + }); + Onyx.update(pushJSON); triggerNotifications(pushJSON); }); From 86853c6689a7e5aca59e244fd36c2f3bb89f69ad Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Fri, 28 Jul 2023 15:28:05 -0600 Subject: [PATCH 04/13] Move code to HTTPS handler --- src/libs/Middleware/SaveResponseInOnyx.js | 18 +++++++++++++++++- .../actions/MemoryOnlyKeys/MemoryOnlyKeys.js | 2 +- src/libs/actions/User.js | 13 ------------- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/libs/Middleware/SaveResponseInOnyx.js b/src/libs/Middleware/SaveResponseInOnyx.js index faecda08df7a..1244ae2a3a3a 100644 --- a/src/libs/Middleware/SaveResponseInOnyx.js +++ b/src/libs/Middleware/SaveResponseInOnyx.js @@ -1,6 +1,22 @@ import Onyx from 'react-native-onyx'; +import _ from 'underscore'; import CONST from '../../CONST'; +import ONYXKEYS from '../../ONYXKEYS'; import * as QueuedOnyxUpdates from '../actions/QueuedOnyxUpdates'; +import * as MemoryOnlyKeys from '../actions/MemoryOnlyKeys/MemoryOnlyKeys'; + +function updateOnyx(updateData) { + // If there is an OnyxUpdate for using memory only keys, enable them + _.each(updateData, ({key, value}) => { + if (key !== ONYXKEYS.IS_USING_MEMORY_ONLY_KEYS || !value) { + return; + } + + MemoryOnlyKeys.enable(); + }); + + return Onyx.update(updateData); +} /** * @param {Promise} response @@ -16,7 +32,7 @@ function SaveResponseInOnyx(response, request) { // For most requests we can immediately update Onyx. For write requests we queue the updates and apply them after the sequential queue has flushed to prevent a replay effect in // the UI. See https://github.com/Expensify/App/issues/12775 for more info. - const updateHandler = request.data.apiRequestType === CONST.API_REQUEST_TYPE.WRITE ? QueuedOnyxUpdates.queueOnyxUpdates : Onyx.update; + const updateHandler = request.data.apiRequestType === CONST.API_REQUEST_TYPE.WRITE ? QueuedOnyxUpdates.queueOnyxUpdates : updateOnyx; // First apply any onyx data updates that are being sent back from the API. We wait for this to complete and then // apply successData or failureData. This ensures that we do not update any pending, loading, or other UI states contained diff --git a/src/libs/actions/MemoryOnlyKeys/MemoryOnlyKeys.js b/src/libs/actions/MemoryOnlyKeys/MemoryOnlyKeys.js index 940e63c44dc4..3b5546ed9ca3 100644 --- a/src/libs/actions/MemoryOnlyKeys/MemoryOnlyKeys.js +++ b/src/libs/actions/MemoryOnlyKeys/MemoryOnlyKeys.js @@ -1,4 +1,4 @@ -import * as Onyx from 'react-native-onyx'; +import Onyx from 'react-native-onyx'; import ONYXKEYS from '../../../ONYXKEYS'; const memoryOnlyKeys = [ONYXKEYS.COLLECTION.REPORT, ONYXKEYS.COLLECTION.POLICY, ONYXKEYS.PERSONAL_DETAILS_LIST]; diff --git a/src/libs/actions/User.js b/src/libs/actions/User.js index 1536cb1791b2..98217e82b5f5 100644 --- a/src/libs/actions/User.js +++ b/src/libs/actions/User.js @@ -18,7 +18,6 @@ import * as ReportActionsUtils from '../ReportActionsUtils'; import * as ErrorUtils from '../ErrorUtils'; import * as Session from './Session'; import * as PersonalDetails from './PersonalDetails'; -import * as MemoryOnlyKeys from './MemoryOnlyKeys/MemoryOnlyKeys'; let currentUserAccountID = ''; let currentEmail = ''; @@ -570,18 +569,6 @@ function subscribeToUserEvents() { return; } - // If there is an OnyxUpdate for using memory only keys, enable or disable the memory only keys according to the value. - _.each(pushJSON, ({key, val}) => { - if (key !== ONYXKEYS.IS_USING_MEMORY_ONLY_KEYS) { - return; - } - if (val) { - MemoryOnlyKeys.enable(); - } else { - MemoryOnlyKeys.disable(); - } - }); - Onyx.update(pushJSON); triggerNotifications(pushJSON); }); From 0b8089498c16c059582fe1b9cda705bbcccbb531 Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Mon, 14 Aug 2023 10:30:37 -0600 Subject: [PATCH 05/13] Finish implementing checks for onyx update --- src/libs/Middleware/SaveResponseInOnyx.js | 27 +++++++++---------- .../actions/MemoryOnlyKeys/MemoryOnlyKeys.js | 4 +-- src/libs/actions/User.js | 10 +++++++ 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/libs/Middleware/SaveResponseInOnyx.js b/src/libs/Middleware/SaveResponseInOnyx.js index 626be8c33e29..a45dad5d7b63 100644 --- a/src/libs/Middleware/SaveResponseInOnyx.js +++ b/src/libs/Middleware/SaveResponseInOnyx.js @@ -4,20 +4,6 @@ import CONST from '../../CONST'; import ONYXKEYS from '../../ONYXKEYS'; import * as QueuedOnyxUpdates from '../actions/QueuedOnyxUpdates'; import * as MemoryOnlyKeys from '../actions/MemoryOnlyKeys/MemoryOnlyKeys'; - -function updateOnyx(updateData) { - // If there is an OnyxUpdate for using memory only keys, enable them - _.each(updateData, ({key, value}) => { - if (key !== ONYXKEYS.IS_USING_MEMORY_ONLY_KEYS || !value) { - return; - } - - MemoryOnlyKeys.enable(); - }); - - return Onyx.update(updateData); -} - import * as OnyxUpdates from '../actions/OnyxUpdates'; /** @@ -32,12 +18,23 @@ function SaveResponseInOnyx(response, request) { return; } + // Supports both the old format and the new format + const onyxUpdates = _.isArray(responseData) ? responseData : responseData.onyxData; + // If there is an OnyxUpdate for using memory only keys, enable them + _.each(onyxUpdates, ({key, value}) => { + if (key !== ONYXKEYS.IS_USING_MEMORY_ONLY_KEYS || !value) { + return; + } + + MemoryOnlyKeys.enable(); + }); + // Save the update IDs to Onyx so they can be used to fetch incremental updates if the client gets out of sync from the server OnyxUpdates.saveUpdateIDs(Number(responseData.lastUpdateID || 0), Number(responseData.previousUpdateID || 0)); // For most requests we can immediately update Onyx. For write requests we queue the updates and apply them after the sequential queue has flushed to prevent a replay effect in // the UI. See https://github.com/Expensify/App/issues/12775 for more info. - const updateHandler = request.data.apiRequestType === CONST.API_REQUEST_TYPE.WRITE ? QueuedOnyxUpdates.queueOnyxUpdates : updateOnyx; + const updateHandler = request.data.apiRequestType === CONST.API_REQUEST_TYPE.WRITE ? QueuedOnyxUpdates.queueOnyxUpdates : Onyx.update; // First apply any onyx data updates that are being sent back from the API. We wait for this to complete and then // apply successData or failureData. This ensures that we do not update any pending, loading, or other UI states contained diff --git a/src/libs/actions/MemoryOnlyKeys/MemoryOnlyKeys.js b/src/libs/actions/MemoryOnlyKeys/MemoryOnlyKeys.js index 3b5546ed9ca3..01e272301eb9 100644 --- a/src/libs/actions/MemoryOnlyKeys/MemoryOnlyKeys.js +++ b/src/libs/actions/MemoryOnlyKeys/MemoryOnlyKeys.js @@ -4,13 +4,13 @@ import ONYXKEYS from '../../../ONYXKEYS'; const memoryOnlyKeys = [ONYXKEYS.COLLECTION.REPORT, ONYXKEYS.COLLECTION.POLICY, ONYXKEYS.PERSONAL_DETAILS_LIST]; const enable = () => { - console.log('Turning on memory only keys'); + console.debug('Turning on memory only keys'); Onyx.set(ONYXKEYS.IS_USING_MEMORY_ONLY_KEYS, true); Onyx.setMemoryOnlyKeys(memoryOnlyKeys); }; const disable = () => { - console.log('Turning off memory only keys'); + console.debug('Turning off memory only keys'); Onyx.set(ONYXKEYS.IS_USING_MEMORY_ONLY_KEYS, false); Onyx.setMemoryOnlyKeys([]); }; diff --git a/src/libs/actions/User.js b/src/libs/actions/User.js index 399581345ddf..f3e8e6d6bcc0 100644 --- a/src/libs/actions/User.js +++ b/src/libs/actions/User.js @@ -19,6 +19,7 @@ import * as ErrorUtils from '../ErrorUtils'; import * as Session from './Session'; import * as PersonalDetails from './PersonalDetails'; import * as OnyxUpdates from './OnyxUpdates'; +import * as MemoryOnlyKeys from './MemoryOnlyKeys/MemoryOnlyKeys'; let currentUserAccountID = ''; let currentEmail = ''; @@ -569,6 +570,15 @@ function subscribeToUserEvents() { return; } + // If there is an OnyxUpdate for using memory only keys, enable them + _.each(pushJSON, ({key, value}) => { + if (key !== ONYXKEYS.IS_USING_MEMORY_ONLY_KEYS || !value) { + return; + } + + MemoryOnlyKeys.enable(); + }); + Onyx.update(pushJSON); triggerNotifications(pushJSON); }); From b09913c876c3936b24bb17b46b9da7d8d2d5b3f7 Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Mon, 14 Aug 2023 10:38:26 -0600 Subject: [PATCH 06/13] Improve debug logs --- src/libs/actions/MemoryOnlyKeys/MemoryOnlyKeys.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/MemoryOnlyKeys/MemoryOnlyKeys.js b/src/libs/actions/MemoryOnlyKeys/MemoryOnlyKeys.js index 01e272301eb9..82ce478754fe 100644 --- a/src/libs/actions/MemoryOnlyKeys/MemoryOnlyKeys.js +++ b/src/libs/actions/MemoryOnlyKeys/MemoryOnlyKeys.js @@ -4,13 +4,13 @@ import ONYXKEYS from '../../../ONYXKEYS'; const memoryOnlyKeys = [ONYXKEYS.COLLECTION.REPORT, ONYXKEYS.COLLECTION.POLICY, ONYXKEYS.PERSONAL_DETAILS_LIST]; const enable = () => { - console.debug('Turning on memory only keys'); + console.debug('[MemoryOnlyKeys] enabled'); Onyx.set(ONYXKEYS.IS_USING_MEMORY_ONLY_KEYS, true); Onyx.setMemoryOnlyKeys(memoryOnlyKeys); }; const disable = () => { - console.debug('Turning off memory only keys'); + console.debug('[MemoryOnlyKeys] disabled'); Onyx.set(ONYXKEYS.IS_USING_MEMORY_ONLY_KEYS, false); Onyx.setMemoryOnlyKeys([]); }; From 0a21797bbfcd48e8235dc2b7ff160f0c2d7cb6fa Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Mon, 14 Aug 2023 10:56:27 -0600 Subject: [PATCH 07/13] Enable memory only keys when guides login --- src/pages/signin/LoginForm.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/pages/signin/LoginForm.js b/src/pages/signin/LoginForm.js index 5f973f7113c1..d814b2f6b099 100644 --- a/src/pages/signin/LoginForm.js +++ b/src/pages/signin/LoginForm.js @@ -29,6 +29,7 @@ import * as PolicyUtils from '../../libs/PolicyUtils'; import Log from '../../libs/Log'; import withNavigationFocus, {withNavigationFocusPropTypes} from '../../components/withNavigationFocus'; import usePrevious from '../../hooks/usePrevious'; +import * as MemoryOnlyKeys from '../../libs/actions/MemoryOnlyKeys/MemoryOnlyKeys'; const propTypes = { /** Should we dismiss the keyboard when transitioning away from the page? */ @@ -71,13 +72,6 @@ const defaultProps = { blurOnSubmit: false, }; -/** - * Enables experimental "memory only keys" mode in Onyx - */ -const setEnableMemoryOnlyKeys = () => { - window.enableMemoryOnlyKeys(); -}; - function LoginForm(props) { const input = useRef(); const [login, setLogin] = useState(''); @@ -142,7 +136,7 @@ function LoginForm(props) { // If the user has entered a guide email, then we are going to enable an experimental Onyx mode to help with performance if (PolicyUtils.isExpensifyGuideTeam(loginTrim)) { Log.info('Detected guide email in login field, setting memory only keys.'); - setEnableMemoryOnlyKeys(); + MemoryOnlyKeys.enable(); } setFormError(null); From 560f56985940b8fbb586692da6c39b501ed1c4c4 Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Fri, 18 Aug 2023 10:25:53 -0600 Subject: [PATCH 08/13] Improve comments, remove unnecessary code --- src/libs/Middleware/SaveResponseInOnyx.js | 9 +++++++++ src/libs/actions/User.js | 18 +++++++----------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/libs/Middleware/SaveResponseInOnyx.js b/src/libs/Middleware/SaveResponseInOnyx.js index a45dad5d7b63..29bedf601c98 100644 --- a/src/libs/Middleware/SaveResponseInOnyx.js +++ b/src/libs/Middleware/SaveResponseInOnyx.js @@ -18,6 +18,15 @@ function SaveResponseInOnyx(response, request) { return; } + // The data for this response comes in two different formats: + // 1. Original format - this is what was sent before the RELIABLE_UPDATES project and will go away once RELIABLE_UPDATES is fully complete + // - The data is an array of objects, where each object is an onyx update + // Example: [{onyxMethod: 'whatever', key: 'foo', value: 'bar'}] + // 1. Reliable updates format - this is what was sent with the RELIABLE_UPDATES project and will be the format from now on + // - The data is an object, containing updateIDs from the server and an array of onyx updates (this array is the same format as the original format above) + // Example: {lastUpdateID: 1, previousUpdateID: 0, onyxData: [{onyxMethod: 'whatever', key: 'foo', value: 'bar'}]} + // NOTE: This is slightly different than the format of the pusher event data, where pusher has "updates" and HTTPS responses have "onyxData" (long story) + // Supports both the old format and the new format const onyxUpdates = _.isArray(responseData) ? responseData : responseData.onyxData; // If there is an OnyxUpdate for using memory only keys, enable them diff --git a/src/libs/actions/User.js b/src/libs/actions/User.js index 911da5da6d26..30adf1c353c2 100644 --- a/src/libs/actions/User.js +++ b/src/libs/actions/User.js @@ -549,8 +549,13 @@ function subscribeToUserEvents() { PusherUtils.subscribeToPrivateUserChannelEvent(Pusher.TYPE.MULTIPLE_EVENTS, currentUserAccountID, (pushJSON) => { let updates; - // This is the old format where each update was just an array, with the new changes it's an object with - // lastUpdateID, previousUpdateID and updates + // The data for this push event comes in two different formats: + // 1. Original format - this is what was sent before the RELIABLE_UPDATES project and will go away once RELIABLE_UPDATES is fully complete + // - The data is an array of objects, where each object is an onyx update + // Example: [{onyxMethod: 'whatever', key: 'foo', value: 'bar'}] + // 1. Reliable updates format - this is what was sent with the RELIABLE_UPDATES project and will be the format from now on + // - The data is an object, containing updateIDs from the server and an array of onyx updates (this array is the same format as the original format above) + // Example: {lastUpdateID: 1, previousUpdateID: 0, updates: [{onyxMethod: 'whatever', key: 'foo', value: 'bar'}]} if (_.isArray(pushJSON)) { updates = pushJSON; } else { @@ -570,15 +575,6 @@ function subscribeToUserEvents() { return; } - // If there is an OnyxUpdate for using memory only keys, enable them - _.each(pushJSON, ({key, value}) => { - if (key !== ONYXKEYS.IS_USING_MEMORY_ONLY_KEYS || !value) { - return; - } - - MemoryOnlyKeys.enable(); - }); - Onyx.update(pushJSON); triggerNotifications(pushJSON); }); From 6b6aaf198a1ec896313f224d9240403daa520084 Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Fri, 18 Aug 2023 10:26:13 -0600 Subject: [PATCH 09/13] Switch underscore method to be more efficient --- src/libs/Middleware/SaveResponseInOnyx.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/Middleware/SaveResponseInOnyx.js b/src/libs/Middleware/SaveResponseInOnyx.js index 29bedf601c98..443cef0bef52 100644 --- a/src/libs/Middleware/SaveResponseInOnyx.js +++ b/src/libs/Middleware/SaveResponseInOnyx.js @@ -30,7 +30,7 @@ function SaveResponseInOnyx(response, request) { // Supports both the old format and the new format const onyxUpdates = _.isArray(responseData) ? responseData : responseData.onyxData; // If there is an OnyxUpdate for using memory only keys, enable them - _.each(onyxUpdates, ({key, value}) => { + _.find(onyxUpdates, ({key, value}) => { if (key !== ONYXKEYS.IS_USING_MEMORY_ONLY_KEYS || !value) { return; } From a9645547bebb05df5408f02711e368c0d488baa0 Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Fri, 18 Aug 2023 10:26:34 -0600 Subject: [PATCH 10/13] Add proper return values --- src/libs/Middleware/SaveResponseInOnyx.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libs/Middleware/SaveResponseInOnyx.js b/src/libs/Middleware/SaveResponseInOnyx.js index 443cef0bef52..28b8a93fb585 100644 --- a/src/libs/Middleware/SaveResponseInOnyx.js +++ b/src/libs/Middleware/SaveResponseInOnyx.js @@ -32,10 +32,11 @@ function SaveResponseInOnyx(response, request) { // If there is an OnyxUpdate for using memory only keys, enable them _.find(onyxUpdates, ({key, value}) => { if (key !== ONYXKEYS.IS_USING_MEMORY_ONLY_KEYS || !value) { - return; + return false; } MemoryOnlyKeys.enable(); + return true; }); // Save the update IDs to Onyx so they can be used to fetch incremental updates if the client gets out of sync from the server From 5b94b18aa1716246b613e6fe9fd1a583bc4b7303 Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Fri, 18 Aug 2023 10:27:50 -0600 Subject: [PATCH 11/13] Change logging to use server logs --- src/libs/actions/MemoryOnlyKeys/MemoryOnlyKeys.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/MemoryOnlyKeys/MemoryOnlyKeys.js b/src/libs/actions/MemoryOnlyKeys/MemoryOnlyKeys.js index 82ce478754fe..d46222189804 100644 --- a/src/libs/actions/MemoryOnlyKeys/MemoryOnlyKeys.js +++ b/src/libs/actions/MemoryOnlyKeys/MemoryOnlyKeys.js @@ -1,16 +1,17 @@ import Onyx from 'react-native-onyx'; import ONYXKEYS from '../../../ONYXKEYS'; +import Log from '../../Log'; const memoryOnlyKeys = [ONYXKEYS.COLLECTION.REPORT, ONYXKEYS.COLLECTION.POLICY, ONYXKEYS.PERSONAL_DETAILS_LIST]; const enable = () => { - console.debug('[MemoryOnlyKeys] enabled'); + Log.info('[MemoryOnlyKeys] enabled'); Onyx.set(ONYXKEYS.IS_USING_MEMORY_ONLY_KEYS, true); Onyx.setMemoryOnlyKeys(memoryOnlyKeys); }; const disable = () => { - console.debug('[MemoryOnlyKeys] disabled'); + Log.info('[MemoryOnlyKeys] disabled'); Onyx.set(ONYXKEYS.IS_USING_MEMORY_ONLY_KEYS, false); Onyx.setMemoryOnlyKeys([]); }; From 825cf66fabbbf7aa3628249b8503a57b2f15a383 Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Fri, 18 Aug 2023 10:28:42 -0600 Subject: [PATCH 12/13] Update method names to match file name --- .../MemoryOnlyKeys/exposeGlobalMemoryOnlyKeysMethods/index.js | 4 ++-- .../exposeGlobalMemoryOnlyKeysMethods/index.native.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libs/actions/MemoryOnlyKeys/exposeGlobalMemoryOnlyKeysMethods/index.js b/src/libs/actions/MemoryOnlyKeys/exposeGlobalMemoryOnlyKeysMethods/index.js index 9935efeabee8..fa62268753db 100644 --- a/src/libs/actions/MemoryOnlyKeys/exposeGlobalMemoryOnlyKeysMethods/index.js +++ b/src/libs/actions/MemoryOnlyKeys/exposeGlobalMemoryOnlyKeysMethods/index.js @@ -1,6 +1,6 @@ import * as MemoryOnlyKeys from '../MemoryOnlyKeys'; -const exposeGlobalMethods = () => { +const exposeGlobalMemoryOnlyKeysMethods = () => { window.enableMemoryOnlyKeys = () => { MemoryOnlyKeys.enable(); }; @@ -9,4 +9,4 @@ const exposeGlobalMethods = () => { }; }; -export default exposeGlobalMethods; +export default exposeGlobalMemoryOnlyKeysMethods; diff --git a/src/libs/actions/MemoryOnlyKeys/exposeGlobalMemoryOnlyKeysMethods/index.native.js b/src/libs/actions/MemoryOnlyKeys/exposeGlobalMemoryOnlyKeysMethods/index.native.js index 3a24512f2495..9d08b9db6aa4 100644 --- a/src/libs/actions/MemoryOnlyKeys/exposeGlobalMemoryOnlyKeysMethods/index.native.js +++ b/src/libs/actions/MemoryOnlyKeys/exposeGlobalMemoryOnlyKeysMethods/index.native.js @@ -1,6 +1,6 @@ /** * This is a no-op because the global methods will only work for web and desktop */ -const exposeGlobalMethods = () => {}; +const exposeGlobalMemoryOnlyKeysMethods = () => {}; -export default exposeGlobalMethods; +export default exposeGlobalMemoryOnlyKeysMethods; From c5d5f61af2168bc9bdb37d88bfe1b2e1443ca416 Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Fri, 18 Aug 2023 13:33:02 -0600 Subject: [PATCH 13/13] Update src/libs/actions/User.js Co-authored-by: Marc Glasser --- src/libs/actions/User.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/actions/User.js b/src/libs/actions/User.js index 30adf1c353c2..b77c5b278bc9 100644 --- a/src/libs/actions/User.js +++ b/src/libs/actions/User.js @@ -19,7 +19,6 @@ import * as ErrorUtils from '../ErrorUtils'; import * as Session from './Session'; import * as PersonalDetails from './PersonalDetails'; import * as OnyxUpdates from './OnyxUpdates'; -import * as MemoryOnlyKeys from './MemoryOnlyKeys/MemoryOnlyKeys'; let currentUserAccountID = ''; let currentEmail = '';