From 32bf6cc003e6960164c43cbe09281ff307dfff1f Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Mon, 24 Jul 2023 16:09:14 -0600 Subject: [PATCH 01/20] Add new method with basic implementation --- src/CONST.js | 1 + src/libs/Navigation/AppNavigator/AuthScreens.js | 2 +- src/libs/actions/App.js | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/CONST.js b/src/CONST.js index 46aa9a1943e9..aac1b402ebb9 100755 --- a/src/CONST.js +++ b/src/CONST.js @@ -686,6 +686,7 @@ const CONST = { SUCCESS: 200, BAD_REQUEST: 400, NOT_AUTHENTICATED: 407, + ONYX_UPDATES_UNAVAILABLE: 423, EXP_ERROR: 666, MANY_WRITES_ERROR: 665, UNABLE_TO_RETRY: 'unableToRetry', diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.js b/src/libs/Navigation/AppNavigator/AuthScreens.js index 44294d40387e..ee0cb8fdf40c 100644 --- a/src/libs/Navigation/AppNavigator/AuthScreens.js +++ b/src/libs/Navigation/AppNavigator/AuthScreens.js @@ -115,7 +115,7 @@ class AuthScreens extends React.Component { componentDidMount() { NetworkConnection.listenForReconnect(); - NetworkConnection.onReconnect(() => App.reconnectApp()); + NetworkConnection.onReconnect(() => App.getMissingOnyxUpdates()); PusherConnectionManager.init(); Pusher.init({ appKey: CONFIG.PUSHER.APP_KEY, diff --git a/src/libs/actions/App.js b/src/libs/actions/App.js index 860d4ce47b91..380da6e7b40b 100644 --- a/src/libs/actions/App.js +++ b/src/libs/actions/App.js @@ -181,6 +181,19 @@ function reconnectApp() { openApp(true); } +function getMissingOnyxUpdates() { + API.makeRequestWithSideEffects('GetMissingOnyxUpdates', { + // @TODO figure out what these values should be + updateIDFrom: 1, + updateIDTo: 2, + }).then((response) => { + // When Onyx updates are unavailable, all data needs to be downloaded from the server by calling reconnectApp(). + if (response.jsonCode === CONST.JSON_CODE.ONYX_UPDATES_UNAVAILABLE) { + reconnectApp(); + } + }); +} + /** * This promise is used so that deeplink component know when a transition is end. * This is necessary because we want to begin deeplink redirection after the transition is end. @@ -357,6 +370,7 @@ export { openProfile, openApp, reconnectApp, + getMissingOnyxUpdates, confirmReadyToOpenApp, beginDeepLinkRedirect, beginDeepLinkRedirectAfterTransition, From 294b6e05ed5660e68c472abf2297802c9d9afa76 Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Tue, 25 Jul 2023 11:32:30 -0600 Subject: [PATCH 02/20] Store update IDs in Onyx --- src/ONYXKEYS.js | 8 ++++++++ src/libs/actions/User.js | 7 +++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/ONYXKEYS.js b/src/ONYXKEYS.js index 5b1640915441..6aca9cb2c3ab 100755 --- a/src/ONYXKEYS.js +++ b/src/ONYXKEYS.js @@ -234,4 +234,12 @@ export default { // Experimental memory only Onyx mode flag IS_USING_MEMORY_ONLY_KEYS: 'isUsingMemoryOnlyKeys', + + ONYX_UPDATES: { + // The ID of the last Onyx update that was applied to this client + LAST_UPDATE_ID: 'onyxUpdatesLastUpdateID', + + // The ID of the previous Onyx update that was applied to this client + PREVIOUS_UPDATE_ID: 'onyxUpdatesPreviousUpdateID', + }, }; diff --git a/src/libs/actions/User.js b/src/libs/actions/User.js index 24ebc13139bc..d819d9899b52 100644 --- a/src/libs/actions/User.js +++ b/src/libs/actions/User.js @@ -539,8 +539,11 @@ function subscribeToUserEvents() { if (_.isArray(pushJSON)) { updates = pushJSON; } else { - // const lastUpdateID = pushJSON.lastUpdateID; - // const previousUpdateID = pushJSON.previousUpdateID; + // Store these values in Onyx so they can be accessed when calling reconnectApp and only retrieve incremental updates + Onyx.multiSet({ + [ONYXKEYS.ONYX_UPDATES.LAST_UPDATE_ID]: pushJSON.lastUpdateID, + [ONYXKEYS.ONYX_UPDATES.PREVIOUS_UPDATE_ID]: pushJSON.previousUpdateID, + }); updates = pushJSON.updates; } _.each(updates, (multipleEvent) => { From fc843830830c36d7d63617550b535fdbb4d545df Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Tue, 25 Jul 2023 11:33:10 -0600 Subject: [PATCH 03/20] Pass update IDs when reconnecting --- src/libs/actions/App.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/libs/actions/App.js b/src/libs/actions/App.js index 380da6e7b40b..36837d1fd6ed 100644 --- a/src/libs/actions/App.js +++ b/src/libs/actions/App.js @@ -42,6 +42,12 @@ Onyx.connect({ callback: (val) => (preferredLocale = val), }); +let onyxUpdatesLastUpdateID; +Onyx.connect({ + key: ONYXKEYS.ONYX_UPDATES.LAST_UPDATE_ID, + callback: (val) => (onyxUpdatesLastUpdateID = val), +}); + let resolveIsReadyPromise; const isReadyToOpenApp = new Promise((resolve) => { resolveIsReadyPromise = resolve; @@ -141,6 +147,10 @@ function openApp(isReconnecting = false) { Timing.start(CONST.TIMING.CALCULATE_MOST_RECENT_LAST_MODIFIED_ACTION); params.mostRecentReportActionLastModified = ReportActionsUtils.getMostRecentReportActionLastModified(); Timing.end(CONST.TIMING.CALCULATE_MOST_RECENT_LAST_MODIFIED_ACTION, '', 500); + + // Include the last update ID when reconnecting so that the server can send incremental updates if they are available. + // Otherwise, a full set of app data will be returned. + params.updateIDFrom = onyxUpdatesLastUpdateID; } Onyx.disconnect(connectionID); From 9192927aac92a1d564bec659f2f8c07a93ba40f9 Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Tue, 25 Jul 2023 11:33:25 -0600 Subject: [PATCH 04/20] Simplify reconnection methods --- .../Navigation/AppNavigator/AuthScreens.js | 11 ++++------ src/libs/actions/App.js | 22 ------------------- 2 files changed, 4 insertions(+), 29 deletions(-) diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.js b/src/libs/Navigation/AppNavigator/AuthScreens.js index ee0cb8fdf40c..989dd3550834 100644 --- a/src/libs/Navigation/AppNavigator/AuthScreens.js +++ b/src/libs/Navigation/AppNavigator/AuthScreens.js @@ -115,7 +115,7 @@ class AuthScreens extends React.Component { componentDidMount() { NetworkConnection.listenForReconnect(); - NetworkConnection.onReconnect(() => App.getMissingOnyxUpdates()); + NetworkConnection.onReconnect(() => App.openApp(true)); PusherConnectionManager.init(); Pusher.init({ appKey: CONFIG.PUSHER.APP_KEY, @@ -126,15 +126,12 @@ class AuthScreens extends React.Component { }); // If we are on this screen then we are "logged in", but the user might not have "just logged in". They could be reopening the app - // or returning from background. If so, we'll assume they have some app data already and we can call reconnectApp() instead of openApp(). + // or returning from background. If so, we'll assume they have some app data already and we can call openApp(true) instead of openApp(). // Note: If a Guide has enabled the memory only key mode then we do want to run OpenApp as their app will not be rehydrated with // the correct state on refresh. They are explicitly opting out of storing data they would need (i.e. reports_) to take advantage of // the optimizations performed during ReconnectApp. - if (this.props.isUsingMemoryOnlyKeys || SessionUtils.didUserLogInDuringSession()) { - App.openApp(); - } else { - App.reconnectApp(); - } + const shouldGetAllData = this.props.isUsingMemoryOnlyKeys || SessionUtils.didUserLogInDuringSession(); + App.openApp(!shouldGetAllData); App.setUpPoliciesAndNavigate(this.props.session, !this.props.isSmallScreenWidth); diff --git a/src/libs/actions/App.js b/src/libs/actions/App.js index 36837d1fd6ed..8d25fbb8411c 100644 --- a/src/libs/actions/App.js +++ b/src/libs/actions/App.js @@ -184,26 +184,6 @@ function openApp(isReconnecting = false) { }); } -/** - * Refreshes data when the app reconnects - */ -function reconnectApp() { - openApp(true); -} - -function getMissingOnyxUpdates() { - API.makeRequestWithSideEffects('GetMissingOnyxUpdates', { - // @TODO figure out what these values should be - updateIDFrom: 1, - updateIDTo: 2, - }).then((response) => { - // When Onyx updates are unavailable, all data needs to be downloaded from the server by calling reconnectApp(). - if (response.jsonCode === CONST.JSON_CODE.ONYX_UPDATES_UNAVAILABLE) { - reconnectApp(); - } - }); -} - /** * This promise is used so that deeplink component know when a transition is end. * This is necessary because we want to begin deeplink redirection after the transition is end. @@ -379,8 +359,6 @@ export { setUpPoliciesAndNavigate, openProfile, openApp, - reconnectApp, - getMissingOnyxUpdates, confirmReadyToOpenApp, beginDeepLinkRedirect, beginDeepLinkRedirectAfterTransition, From 18104e7531b02690045a66c5a1de18286b2035c0 Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Tue, 25 Jul 2023 11:35:42 -0600 Subject: [PATCH 05/20] Remove unused constant --- src/CONST.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/CONST.js b/src/CONST.js index aac1b402ebb9..46aa9a1943e9 100755 --- a/src/CONST.js +++ b/src/CONST.js @@ -686,7 +686,6 @@ const CONST = { SUCCESS: 200, BAD_REQUEST: 400, NOT_AUTHENTICATED: 407, - ONYX_UPDATES_UNAVAILABLE: 423, EXP_ERROR: 666, MANY_WRITES_ERROR: 665, UNABLE_TO_RETRY: 'unableToRetry', From 85b50ea7466fe9ac6b9e970d61dfd57120571390 Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Tue, 25 Jul 2023 11:38:18 -0600 Subject: [PATCH 06/20] Change param name --- src/libs/actions/App.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libs/actions/App.js b/src/libs/actions/App.js index 8d25fbb8411c..fbdb20715c55 100644 --- a/src/libs/actions/App.js +++ b/src/libs/actions/App.js @@ -129,9 +129,9 @@ AppState.addEventListener('change', (nextAppState) => { /** * Fetches data needed for app initialization - * @param {boolean} [isReconnecting] + * @param {boolean} [fetchIncrementalUpdates] When the app is reconnecting from a previous session, incremental updates are preferred so that there is less data being transferred */ -function openApp(isReconnecting = false) { +function openApp(fetchIncrementalUpdates = false) { isReadyToOpenApp.then(() => { const connectionID = Onyx.connect({ key: ONYXKEYS.COLLECTION.POLICY, @@ -143,7 +143,7 @@ function openApp(isReconnecting = false) { // - Look through the local report actions and reports to find the most recently modified report action or report. // - We send this to the server so that it can compute which new chats the user needs to see and return only those as an optimization. const params = {policyIDList: getNonOptimisticPolicyIDs(policies)}; - if (isReconnecting) { + if (fetchIncrementalUpdates) { Timing.start(CONST.TIMING.CALCULATE_MOST_RECENT_LAST_MODIFIED_ACTION); params.mostRecentReportActionLastModified = ReportActionsUtils.getMostRecentReportActionLastModified(); Timing.end(CONST.TIMING.CALCULATE_MOST_RECENT_LAST_MODIFIED_ACTION, '', 500); @@ -155,8 +155,8 @@ function openApp(isReconnecting = false) { Onyx.disconnect(connectionID); // eslint-disable-next-line rulesdir/no-multiple-api-calls - const apiMethod = isReconnecting ? API.write : API.read; - apiMethod(isReconnecting ? 'ReconnectApp' : 'OpenApp', params, { + const apiMethod = fetchIncrementalUpdates ? API.write : API.read; + apiMethod(fetchIncrementalUpdates ? 'ReconnectApp' : 'OpenApp', params, { optimisticData: [ { onyxMethod: Onyx.METHOD.MERGE, From 1bfdc5644cbe43adaad7d7432270cdf6f8f8fc2d Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Tue, 25 Jul 2023 11:39:00 -0600 Subject: [PATCH 07/20] Update comment --- src/libs/actions/User.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/User.js b/src/libs/actions/User.js index d819d9899b52..d40412246d8c 100644 --- a/src/libs/actions/User.js +++ b/src/libs/actions/User.js @@ -539,7 +539,7 @@ function subscribeToUserEvents() { if (_.isArray(pushJSON)) { updates = pushJSON; } else { - // Store these values in Onyx so they can be accessed when calling reconnectApp and only retrieve incremental updates + // Store these values in Onyx so they can be accessed when openApp() is called and we are reconnecting to a previous session Onyx.multiSet({ [ONYXKEYS.ONYX_UPDATES.LAST_UPDATE_ID]: pushJSON.lastUpdateID, [ONYXKEYS.ONYX_UPDATES.PREVIOUS_UPDATE_ID]: pushJSON.previousUpdateID, From 0414c37a066824fe0606507ee985a2fdb144d9b0 Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Wed, 26 Jul 2023 11:38:35 -0600 Subject: [PATCH 08/20] Correct param and improve a comment --- src/libs/actions/App.js | 2 +- src/libs/actions/User.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/App.js b/src/libs/actions/App.js index fbdb20715c55..a6259f68fd34 100644 --- a/src/libs/actions/App.js +++ b/src/libs/actions/App.js @@ -150,7 +150,7 @@ function openApp(fetchIncrementalUpdates = false) { // Include the last update ID when reconnecting so that the server can send incremental updates if they are available. // Otherwise, a full set of app data will be returned. - params.updateIDFrom = onyxUpdatesLastUpdateID; + params.updateIDTo = onyxUpdatesLastUpdateID; } Onyx.disconnect(connectionID); diff --git a/src/libs/actions/User.js b/src/libs/actions/User.js index d40412246d8c..7a0c4bfac6c5 100644 --- a/src/libs/actions/User.js +++ b/src/libs/actions/User.js @@ -539,7 +539,7 @@ function subscribeToUserEvents() { if (_.isArray(pushJSON)) { updates = pushJSON; } else { - // Store these values in Onyx so they can be accessed when openApp() is called and we are reconnecting to a previous session + // Store these values in Onyx to allow App.openApp(true) to fetch incremental updates from the server when a previous session is being reconnected to. Onyx.multiSet({ [ONYXKEYS.ONYX_UPDATES.LAST_UPDATE_ID]: pushJSON.lastUpdateID, [ONYXKEYS.ONYX_UPDATES.PREVIOUS_UPDATE_ID]: pushJSON.previousUpdateID, From aa9a4b631b048387a970b34c164045514a7ffd41 Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Wed, 26 Jul 2023 11:53:02 -0600 Subject: [PATCH 09/20] Improve the handling of update IDs when reconnecting --- .../Navigation/AppNavigator/AuthScreens.js | 10 +++++++--- src/libs/actions/App.js | 20 ++++++++++--------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.js b/src/libs/Navigation/AppNavigator/AuthScreens.js index 989dd3550834..f943b8527d36 100644 --- a/src/libs/Navigation/AppNavigator/AuthScreens.js +++ b/src/libs/Navigation/AppNavigator/AuthScreens.js @@ -95,6 +95,9 @@ const propTypes = { /** Opt-in experimental mode that prevents certain Onyx keys from persisting to disk */ isUsingMemoryOnlyKeys: PropTypes.bool, + /** The last Onyx update ID that is stored in Onyx (used for getting incremental updates when reconnecting) */ + onyxUpdatesLastUpdateID: PropTypes.number, + ...windowDimensionsPropTypes, }; @@ -104,6 +107,7 @@ const defaultProps = { email: null, }, lastOpenedPublicRoomID: null, + onyxUpdatesLastUpdateID: 0, }; class AuthScreens extends React.Component { @@ -115,7 +119,7 @@ class AuthScreens extends React.Component { componentDidMount() { NetworkConnection.listenForReconnect(); - NetworkConnection.onReconnect(() => App.openApp(true)); + NetworkConnection.onReconnect(() => App.openApp(true, this.props.onyxUpdatesLastUpdateID)); PusherConnectionManager.init(); Pusher.init({ appKey: CONFIG.PUSHER.APP_KEY, @@ -316,8 +320,8 @@ export default compose( lastOpenedPublicRoomID: { key: ONYXKEYS.LAST_OPENED_PUBLIC_ROOM_ID, }, - isUsingMemoryOnlyKeys: { - key: ONYXKEYS.IS_USING_MEMORY_ONLY_KEYS, + onyxUpdatesLastUpdateID: { + key: ONYXKEYS.ONYX_UPDATES.LAST_UPDATE_ID, }, }), )(AuthScreens); diff --git a/src/libs/actions/App.js b/src/libs/actions/App.js index a6259f68fd34..db6234af3917 100644 --- a/src/libs/actions/App.js +++ b/src/libs/actions/App.js @@ -42,12 +42,6 @@ Onyx.connect({ callback: (val) => (preferredLocale = val), }); -let onyxUpdatesLastUpdateID; -Onyx.connect({ - key: ONYXKEYS.ONYX_UPDATES.LAST_UPDATE_ID, - callback: (val) => (onyxUpdatesLastUpdateID = val), -}); - let resolveIsReadyPromise; const isReadyToOpenApp = new Promise((resolve) => { resolveIsReadyPromise = resolve; @@ -130,8 +124,10 @@ AppState.addEventListener('change', (nextAppState) => { /** * Fetches data needed for app initialization * @param {boolean} [fetchIncrementalUpdates] When the app is reconnecting from a previous session, incremental updates are preferred so that there is less data being transferred + * @param {Number} [updateIDFrom] the ID of the Onyx update that we want to start fetching from + * @param {Number} [updateIDTo] the ID of the Onyx update that we want to fetch up to */ -function openApp(fetchIncrementalUpdates = false) { +function openApp(fetchIncrementalUpdates = false, updateIDFrom = 0, updateIDTo = 0) { isReadyToOpenApp.then(() => { const connectionID = Onyx.connect({ key: ONYXKEYS.COLLECTION.POLICY, @@ -148,9 +144,15 @@ function openApp(fetchIncrementalUpdates = false) { params.mostRecentReportActionLastModified = ReportActionsUtils.getMostRecentReportActionLastModified(); Timing.end(CONST.TIMING.CALCULATE_MOST_RECENT_LAST_MODIFIED_ACTION, '', 500); - // Include the last update ID when reconnecting so that the server can send incremental updates if they are available. + // Include the update IDs when reconnecting so that the server can send incremental updates if they are available. // Otherwise, a full set of app data will be returned. - params.updateIDTo = onyxUpdatesLastUpdateID; + if (updateIDFrom) { + params.updateIDFrom = updateIDFrom; + } + + if (updateIDTo) { + params.updateIDTo = updateIDTo; + } } Onyx.disconnect(connectionID); From 2c89bf3a91daa571b5b3ec3f564035adca5f8f93 Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Tue, 1 Aug 2023 08:32:19 -0600 Subject: [PATCH 10/20] Replace key from bad merge --- src/libs/Navigation/AppNavigator/AuthScreens.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.js b/src/libs/Navigation/AppNavigator/AuthScreens.js index 6fd97ee65a6d..dcff9a2983af 100644 --- a/src/libs/Navigation/AppNavigator/AuthScreens.js +++ b/src/libs/Navigation/AppNavigator/AuthScreens.js @@ -321,6 +321,9 @@ export default compose( lastOpenedPublicRoomID: { key: ONYXKEYS.LAST_OPENED_PUBLIC_ROOM_ID, }, + isUsingMemoryOnlyKeys: { + key: ONYXKEYS.IS_USING_MEMORY_ONLY_KEYS, + }, onyxUpdatesLastUpdateID: { key: ONYXKEYS.ONYX_UPDATES.LAST_UPDATE_ID, }, From decaf87591a35535db1892276508cae8e7387dea Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Tue, 1 Aug 2023 08:41:48 -0600 Subject: [PATCH 11/20] Refactor and DRY code --- .../Navigation/AppNavigator/AuthScreens.js | 8 +- src/libs/actions/App.js | 79 ++++++++++++++----- src/libs/actions/User.js | 2 +- 3 files changed, 65 insertions(+), 24 deletions(-) diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.js b/src/libs/Navigation/AppNavigator/AuthScreens.js index dcff9a2983af..00431dab8887 100644 --- a/src/libs/Navigation/AppNavigator/AuthScreens.js +++ b/src/libs/Navigation/AppNavigator/AuthScreens.js @@ -120,7 +120,7 @@ class AuthScreens extends React.Component { componentDidMount() { NetworkConnection.listenForReconnect(); - NetworkConnection.onReconnect(() => App.openApp(true, this.props.onyxUpdatesLastUpdateID)); + NetworkConnection.onReconnect(() => App.reconnectApp(this.props.onyxUpdatesLastUpdateID)); PusherConnectionManager.init(); Pusher.init({ appKey: CONFIG.PUSHER.APP_KEY, @@ -136,7 +136,11 @@ class AuthScreens extends React.Component { // the correct state on refresh. They are explicitly opting out of storing data they would need (i.e. reports_) to take advantage of // the optimizations performed during ReconnectApp. const shouldGetAllData = this.props.isUsingMemoryOnlyKeys || SessionUtils.didUserLogInDuringSession(); - App.openApp(!shouldGetAllData); + if (shouldGetAllData) { + App.openApp(); + } else { + App.reconnectApp(this.props.onyxUpdatesLastUpdateID); + } App.setUpPoliciesAndNavigate(this.props.session, !this.props.isSmallScreenWidth); diff --git a/src/libs/actions/App.js b/src/libs/actions/App.js index 2b62f84c3020..afef27f15fe2 100644 --- a/src/libs/actions/App.js +++ b/src/libs/actions/App.js @@ -135,42 +135,78 @@ AppState.addEventListener('change', (nextAppState) => { /** * Fetches data needed for app initialization - * @param {boolean} [fetchIncrementalUpdates] When the app is reconnecting from a previous session, incremental updates are preferred so that there is less data being transferred + */ +function openApp() { + isReadyToOpenApp.then(() => { + const connectionID = Onyx.connect({ + key: ONYXKEYS.COLLECTION.POLICY, + waitForCollectionCallback: true, + callback: (policies) => { + Onyx.disconnect(connectionID); + const params = {policyIDList: getNonOptimisticPolicyIDs(policies), policyIDToLastModified: JSON.stringify(getNonOptimisticPolicyIDToLastModifiedMap(policies))}; + + API.read('OpenApp', params, { + optimisticData: [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.IS_LOADING_REPORT_DATA, + value: true, + }, + ], + successData: [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.IS_LOADING_REPORT_DATA, + value: false, + }, + ], + failureData: [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.IS_LOADING_REPORT_DATA, + value: false, + }, + ], + }); + }, + }); + }); +} + +/** + * Fetches data when the app reconnects to the network * @param {Number} [updateIDFrom] the ID of the Onyx update that we want to start fetching from * @param {Number} [updateIDTo] the ID of the Onyx update that we want to fetch up to */ -function openApp(fetchIncrementalUpdates = false, updateIDFrom = 0, updateIDTo = 0) { +function reconnectApp(updateIDFrom = 0, updateIDTo = 0) { isReadyToOpenApp.then(() => { const connectionID = Onyx.connect({ key: ONYXKEYS.COLLECTION.POLICY, waitForCollectionCallback: true, callback: (policies) => { + Onyx.disconnect(connectionID); + const params = {policyIDList: getNonOptimisticPolicyIDs(policies), policyIDToLastModified: JSON.stringify(getNonOptimisticPolicyIDToLastModifiedMap(policies))}; + // When the app reconnects we do a fast "sync" of the LHN and only return chats that have new messages. We achieve this by sending the most recent reportActionID. // we have locally. And then only update the user about chats with messages that have occurred after that reportActionID. // // - Look through the local report actions and reports to find the most recently modified report action or report. // - We send this to the server so that it can compute which new chats the user needs to see and return only those as an optimization. - const params = {policyIDList: getNonOptimisticPolicyIDs(policies), policyIDToLastModified: JSON.stringify(getNonOptimisticPolicyIDToLastModifiedMap(policies))}; - if (fetchIncrementalUpdates) { - Timing.start(CONST.TIMING.CALCULATE_MOST_RECENT_LAST_MODIFIED_ACTION); - params.mostRecentReportActionLastModified = ReportActionsUtils.getMostRecentReportActionLastModified(); - Timing.end(CONST.TIMING.CALCULATE_MOST_RECENT_LAST_MODIFIED_ACTION, '', 500); - - // Include the update IDs when reconnecting so that the server can send incremental updates if they are available. - // Otherwise, a full set of app data will be returned. - if (updateIDFrom) { - params.updateIDFrom = updateIDFrom; - } - - if (updateIDTo) { - params.updateIDTo = updateIDTo; - } + Timing.start(CONST.TIMING.CALCULATE_MOST_RECENT_LAST_MODIFIED_ACTION); + params.mostRecentReportActionLastModified = ReportActionsUtils.getMostRecentReportActionLastModified(); + Timing.end(CONST.TIMING.CALCULATE_MOST_RECENT_LAST_MODIFIED_ACTION, '', 500); + + // Include the update IDs when reconnecting so that the server can send incremental updates if they are available. + // Otherwise, a full set of app data will be returned. + if (updateIDFrom) { + params.updateIDFrom = updateIDFrom; + } + + if (updateIDTo) { + params.updateIDTo = updateIDTo; } - Onyx.disconnect(connectionID); - // eslint-disable-next-line rulesdir/no-multiple-api-calls - const apiMethod = fetchIncrementalUpdates ? API.write : API.read; - apiMethod(fetchIncrementalUpdates ? 'ReconnectApp' : 'OpenApp', params, { + API.write('ReconnectApp', params, { optimisticData: [ { onyxMethod: Onyx.METHOD.MERGE, @@ -373,6 +409,7 @@ export { setUpPoliciesAndNavigate, openProfile, openApp, + reconnectApp, confirmReadyToOpenApp, beginDeepLinkRedirect, beginDeepLinkRedirectAfterTransition, diff --git a/src/libs/actions/User.js b/src/libs/actions/User.js index ff5cf62a28ea..7e3f7892dc0e 100644 --- a/src/libs/actions/User.js +++ b/src/libs/actions/User.js @@ -552,7 +552,7 @@ function subscribeToUserEvents() { if (_.isArray(pushJSON)) { updates = pushJSON; } else { - // Store these values in Onyx to allow App.openApp(true) to fetch incremental updates from the server when a previous session is being reconnected to. + // Store these values in Onyx to allow App.reconnectApp() to fetch incremental updates from the server when a previous session is being reconnected to. Onyx.multiSet({ [ONYXKEYS.ONYX_UPDATES.LAST_UPDATE_ID]: pushJSON.lastUpdateID, [ONYXKEYS.ONYX_UPDATES.PREVIOUS_UPDATE_ID]: pushJSON.previousUpdateID, From c2cf0ce8c25e6085f3cbfb12d3e353a77b16fbdc Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Tue, 1 Aug 2023 08:47:57 -0600 Subject: [PATCH 12/20] DRY the code even more --- src/libs/actions/App.js | 159 +++++++++++++++++++--------------------- 1 file changed, 74 insertions(+), 85 deletions(-) diff --git a/src/libs/actions/App.js b/src/libs/actions/App.js index afef27f15fe2..20fe201004a9 100644 --- a/src/libs/actions/App.js +++ b/src/libs/actions/App.js @@ -133,43 +133,61 @@ AppState.addEventListener('change', (nextAppState) => { appState = nextAppState; }); +/** + * Gets the policy IDs that are passed to the server in the OpenApp and ReconnectApp API commands. This includes a full list of policy IDs the client knows about as well as when they were last modified. + * @returns {Object} + */ +function getPolicyIDsForOpenOrReconnect() { + return new Promise((resolve) => { + isReadyToOpenApp.then(() => { + const connectionID = Onyx.connect({ + key: ONYXKEYS.COLLECTION.POLICY, + waitForCollectionCallback: true, + callback: (policies) => { + Onyx.disconnect(connectionID); + resolve({policyIDList: getNonOptimisticPolicyIDs(policies), policyIDToLastModified: JSON.stringify(getNonOptimisticPolicyIDToLastModifiedMap(policies))}); + }, + }); + }); + }); +} + +/** + * Returns the Onyx data that is used for both the OpenApp and ReconnectApp API commands. + * @returns {Object} + */ +function getOnyxDataForOpenOrReconnect() { + return { + optimisticData: [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.IS_LOADING_REPORT_DATA, + value: true, + }, + ], + successData: [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.IS_LOADING_REPORT_DATA, + value: false, + }, + ], + failureData: [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.IS_LOADING_REPORT_DATA, + value: false, + }, + ], + }; +} + /** * Fetches data needed for app initialization */ function openApp() { - isReadyToOpenApp.then(() => { - const connectionID = Onyx.connect({ - key: ONYXKEYS.COLLECTION.POLICY, - waitForCollectionCallback: true, - callback: (policies) => { - Onyx.disconnect(connectionID); - const params = {policyIDList: getNonOptimisticPolicyIDs(policies), policyIDToLastModified: JSON.stringify(getNonOptimisticPolicyIDToLastModifiedMap(policies))}; - - API.read('OpenApp', params, { - optimisticData: [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: ONYXKEYS.IS_LOADING_REPORT_DATA, - value: true, - }, - ], - successData: [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: ONYXKEYS.IS_LOADING_REPORT_DATA, - value: false, - }, - ], - failureData: [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: ONYXKEYS.IS_LOADING_REPORT_DATA, - value: false, - }, - ], - }); - }, - }); + getPolicyIDsForOpenOrReconnect().then((policyIDs) => { + API.read('OpenApp', policyIDs, getOnyxDataForOpenOrReconnect()); }); } @@ -179,58 +197,29 @@ function openApp() { * @param {Number} [updateIDTo] the ID of the Onyx update that we want to fetch up to */ function reconnectApp(updateIDFrom = 0, updateIDTo = 0) { - isReadyToOpenApp.then(() => { - const connectionID = Onyx.connect({ - key: ONYXKEYS.COLLECTION.POLICY, - waitForCollectionCallback: true, - callback: (policies) => { - Onyx.disconnect(connectionID); - const params = {policyIDList: getNonOptimisticPolicyIDs(policies), policyIDToLastModified: JSON.stringify(getNonOptimisticPolicyIDToLastModifiedMap(policies))}; - - // When the app reconnects we do a fast "sync" of the LHN and only return chats that have new messages. We achieve this by sending the most recent reportActionID. - // we have locally. And then only update the user about chats with messages that have occurred after that reportActionID. - // - // - Look through the local report actions and reports to find the most recently modified report action or report. - // - We send this to the server so that it can compute which new chats the user needs to see and return only those as an optimization. - Timing.start(CONST.TIMING.CALCULATE_MOST_RECENT_LAST_MODIFIED_ACTION); - params.mostRecentReportActionLastModified = ReportActionsUtils.getMostRecentReportActionLastModified(); - Timing.end(CONST.TIMING.CALCULATE_MOST_RECENT_LAST_MODIFIED_ACTION, '', 500); - - // Include the update IDs when reconnecting so that the server can send incremental updates if they are available. - // Otherwise, a full set of app data will be returned. - if (updateIDFrom) { - params.updateIDFrom = updateIDFrom; - } - - if (updateIDTo) { - params.updateIDTo = updateIDTo; - } - - API.write('ReconnectApp', params, { - optimisticData: [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: ONYXKEYS.IS_LOADING_REPORT_DATA, - value: true, - }, - ], - successData: [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: ONYXKEYS.IS_LOADING_REPORT_DATA, - value: false, - }, - ], - failureData: [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: ONYXKEYS.IS_LOADING_REPORT_DATA, - value: false, - }, - ], - }); - }, - }); + getPolicyIDsForOpenOrReconnect().then((policyIDs) => { + const params = {...policyIDs}; + + // When the app reconnects we do a fast "sync" of the LHN and only return chats that have new messages. We achieve this by sending the most recent reportActionID. + // we have locally. And then only update the user about chats with messages that have occurred after that reportActionID. + // + // - Look through the local report actions and reports to find the most recently modified report action or report. + // - We send this to the server so that it can compute which new chats the user needs to see and return only those as an optimization. + Timing.start(CONST.TIMING.CALCULATE_MOST_RECENT_LAST_MODIFIED_ACTION); + params.mostRecentReportActionLastModified = ReportActionsUtils.getMostRecentReportActionLastModified(); + Timing.end(CONST.TIMING.CALCULATE_MOST_RECENT_LAST_MODIFIED_ACTION, '', 500); + + // Include the update IDs when reconnecting so that the server can send incremental updates if they are available. + // Otherwise, a full set of app data will be returned. + if (updateIDFrom) { + params.updateIDFrom = updateIDFrom; + } + + if (updateIDTo) { + params.updateIDTo = updateIDTo; + } + + API.write('ReconnectApp', params, getOnyxDataForOpenOrReconnect()); }); } From 826942ef35221fc3eac1f7ed32276a60c3befa98 Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Tue, 1 Aug 2023 10:33:42 -0600 Subject: [PATCH 13/20] Add some logging --- src/libs/actions/App.js | 1 + src/libs/actions/User.js | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/libs/actions/App.js b/src/libs/actions/App.js index 20fe201004a9..90841c56533e 100644 --- a/src/libs/actions/App.js +++ b/src/libs/actions/App.js @@ -197,6 +197,7 @@ function openApp() { * @param {Number} [updateIDTo] the ID of the Onyx update that we want to fetch up to */ function reconnectApp(updateIDFrom = 0, updateIDTo = 0) { + console.debug(`[Onyx Updates] App reconnecting with updateIDFrom: ${updateIDFrom} and updateIDTo: ${updateIDTo}`); getPolicyIDsForOpenOrReconnect().then((policyIDs) => { const params = {...policyIDs}; diff --git a/src/libs/actions/User.js b/src/libs/actions/User.js index 7e3f7892dc0e..eb60f75f7b93 100644 --- a/src/libs/actions/User.js +++ b/src/libs/actions/User.js @@ -558,6 +558,8 @@ function subscribeToUserEvents() { [ONYXKEYS.ONYX_UPDATES.PREVIOUS_UPDATE_ID]: pushJSON.previousUpdateID, }); updates = pushJSON.updates; + console.debug('[Onyx Updates] Received lastUpdateID from pusher', pushJSON.lastUpdateID); + console.debug('[Onyx Updates] Received previousUpdateID from pusher', pushJSON.previousUpdateID); } _.each(updates, (multipleEvent) => { PusherUtils.triggerMultiEventHandler(multipleEvent.eventType, multipleEvent.data); From bd05078fb490c651880676b767c798a2f7f0fd3c Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Tue, 1 Aug 2023 15:42:58 -0600 Subject: [PATCH 14/20] Update log to be more searchable --- src/libs/actions/App.js | 2 +- src/libs/actions/User.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/actions/App.js b/src/libs/actions/App.js index 90841c56533e..07cbfedf59ae 100644 --- a/src/libs/actions/App.js +++ b/src/libs/actions/App.js @@ -197,7 +197,7 @@ function openApp() { * @param {Number} [updateIDTo] the ID of the Onyx update that we want to fetch up to */ function reconnectApp(updateIDFrom = 0, updateIDTo = 0) { - console.debug(`[Onyx Updates] App reconnecting with updateIDFrom: ${updateIDFrom} and updateIDTo: ${updateIDTo}`); + console.debug(`[OnyxUpdates] App reconnecting with updateIDFrom: ${updateIDFrom} and updateIDTo: ${updateIDTo}`); getPolicyIDsForOpenOrReconnect().then((policyIDs) => { const params = {...policyIDs}; diff --git a/src/libs/actions/User.js b/src/libs/actions/User.js index eb60f75f7b93..25a9182b2aa9 100644 --- a/src/libs/actions/User.js +++ b/src/libs/actions/User.js @@ -558,8 +558,8 @@ function subscribeToUserEvents() { [ONYXKEYS.ONYX_UPDATES.PREVIOUS_UPDATE_ID]: pushJSON.previousUpdateID, }); updates = pushJSON.updates; - console.debug('[Onyx Updates] Received lastUpdateID from pusher', pushJSON.lastUpdateID); - console.debug('[Onyx Updates] Received previousUpdateID from pusher', pushJSON.previousUpdateID); + console.debug('[OnyxUpdates] Received lastUpdateID from pusher', pushJSON.lastUpdateID); + console.debug('[OnyxUpdates] Received previousUpdateID from pusher', pushJSON.previousUpdateID); } _.each(updates, (multipleEvent) => { PusherUtils.triggerMultiEventHandler(multipleEvent.eventType, multipleEvent.data); From 581ad3d8250cecc7d9c91e5a3ffdf5cd751a08af Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Wed, 2 Aug 2023 11:16:12 -0600 Subject: [PATCH 15/20] Cast to string and default to 0 --- src/libs/actions/User.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/User.js b/src/libs/actions/User.js index 25a9182b2aa9..4d0729458587 100644 --- a/src/libs/actions/User.js +++ b/src/libs/actions/User.js @@ -558,8 +558,8 @@ function subscribeToUserEvents() { [ONYXKEYS.ONYX_UPDATES.PREVIOUS_UPDATE_ID]: pushJSON.previousUpdateID, }); updates = pushJSON.updates; - console.debug('[OnyxUpdates] Received lastUpdateID from pusher', pushJSON.lastUpdateID); - console.debug('[OnyxUpdates] Received previousUpdateID from pusher', pushJSON.previousUpdateID); + console.debug('[OnyxUpdates] Received lastUpdateID from pusher', Number(pushJSON.lastUpdateID || 0)); + console.debug('[OnyxUpdates] Received previousUpdateID from pusher', Number(pushJSON.previousUpdateID || 0)); } _.each(updates, (multipleEvent) => { PusherUtils.triggerMultiEventHandler(multipleEvent.eventType, multipleEvent.data); From 3aa86f749c0aef56aceba06a9ea319d4d2313aa8 Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Wed, 2 Aug 2023 11:30:55 -0600 Subject: [PATCH 16/20] Move integer casting to storage --- src/libs/actions/User.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libs/actions/User.js b/src/libs/actions/User.js index 4d0729458587..cf72018df02a 100644 --- a/src/libs/actions/User.js +++ b/src/libs/actions/User.js @@ -554,12 +554,12 @@ function subscribeToUserEvents() { } else { // Store these values in Onyx to allow App.reconnectApp() to fetch incremental updates from the server when a previous session is being reconnected to. Onyx.multiSet({ - [ONYXKEYS.ONYX_UPDATES.LAST_UPDATE_ID]: pushJSON.lastUpdateID, - [ONYXKEYS.ONYX_UPDATES.PREVIOUS_UPDATE_ID]: pushJSON.previousUpdateID, + [ONYXKEYS.ONYX_UPDATES.LAST_UPDATE_ID]: Number(pushJSON.lastUpdateID || 0), + [ONYXKEYS.ONYX_UPDATES.PREVIOUS_UPDATE_ID]: Number(pushJSON.previousUpdateID || 0), }); updates = pushJSON.updates; - console.debug('[OnyxUpdates] Received lastUpdateID from pusher', Number(pushJSON.lastUpdateID || 0)); - console.debug('[OnyxUpdates] Received previousUpdateID from pusher', Number(pushJSON.previousUpdateID || 0)); + console.debug('[OnyxUpdates] Received lastUpdateID from pusher', pushJSON.lastUpdateID); + console.debug('[OnyxUpdates] Received previousUpdateID from pusher', pushJSON.previousUpdateID); } _.each(updates, (multipleEvent) => { PusherUtils.triggerMultiEventHandler(multipleEvent.eventType, multipleEvent.data); From c48276d1da7f2964349a21616c120f401e6e2f25 Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Thu, 3 Aug 2023 12:13:21 -0700 Subject: [PATCH 17/20] addressing comments --- src/libs/actions/App.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/App.js b/src/libs/actions/App.js index 46ea3c82d628..ca03380368c2 100644 --- a/src/libs/actions/App.js +++ b/src/libs/actions/App.js @@ -122,8 +122,8 @@ AppState.addEventListener('change', (nextAppState) => { }); /** - * Gets the policy IDs that are passed to the server in the OpenApp and ReconnectApp API commands. This includes a full list of policy IDs the client knows about as well as when they were last modified. - * @returns {Object} + * Gets the policy params that are passed to the server in the OpenApp and ReconnectApp API commands. This includes a full list of policy IDs the client knows about as well as when they were last modified. + * @returns {Promise} */ function getPolicyParamsForOpenOrReconnect() { return new Promise((resolve) => { From cc8152c48f2b7260f59a894a3a92822267db5009 Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Thu, 3 Aug 2023 12:40:52 -0700 Subject: [PATCH 18/20] adding check for lastUpdateId and previousUpdateID --- src/libs/actions/User.js | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/libs/actions/User.js b/src/libs/actions/User.js index cf72018df02a..5e8156151cba 100644 --- a/src/libs/actions/User.js +++ b/src/libs/actions/User.js @@ -552,14 +552,22 @@ function subscribeToUserEvents() { if (_.isArray(pushJSON)) { updates = pushJSON; } else { - // Store these values in Onyx to allow App.reconnectApp() to fetch incremental updates from the server when a previous session is being reconnected to. - Onyx.multiSet({ - [ONYXKEYS.ONYX_UPDATES.LAST_UPDATE_ID]: Number(pushJSON.lastUpdateID || 0), - [ONYXKEYS.ONYX_UPDATES.PREVIOUS_UPDATE_ID]: Number(pushJSON.previousUpdateID || 0), - }); updates = pushJSON.updates; - console.debug('[OnyxUpdates] Received lastUpdateID from pusher', pushJSON.lastUpdateID); - console.debug('[OnyxUpdates] Received previousUpdateID from pusher', pushJSON.previousUpdateID); + + // Not always we'll have the lastUpdateID and previousUpdateID properties in the pusher update + // until we finish the migration to reliable updates. So let's check it before actually updating + // the properties in Onyx + if('lastUpdateID' in pushJSON && 'previousUpdateID' in pushJSON) { + console.debug('[OnyxUpdates] Received lastUpdateID from pusher', pushJSON.lastUpdateID); + console.debug('[OnyxUpdates] Received previousUpdateID from pusher', pushJSON.previousUpdateID); + // Store these values in Onyx to allow App.reconnectApp() to fetch incremental updates from the server when a previous session is being reconnected to. + Onyx.multiSet({ + [ONYXKEYS.ONYX_UPDATES.LAST_UPDATE_ID]: Number(pushJSON.lastUpdateID || 0), + [ONYXKEYS.ONYX_UPDATES.PREVIOUS_UPDATE_ID]: Number(pushJSON.previousUpdateID || 0), + }); + } else { + console.debug('[OnyxUpdates] No lastUpdateID and previousUpdateID provided'); + } } _.each(updates, (multipleEvent) => { PusherUtils.triggerMultiEventHandler(multipleEvent.eventType, multipleEvent.data); From 9a5c233c6eac1b8748985a7dc1820920c350a65b Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Thu, 3 Aug 2023 13:25:22 -0700 Subject: [PATCH 19/20] prettier fixes --- src/libs/actions/User.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/User.js b/src/libs/actions/User.js index 5e8156151cba..224e8a461fbb 100644 --- a/src/libs/actions/User.js +++ b/src/libs/actions/User.js @@ -557,7 +557,7 @@ function subscribeToUserEvents() { // Not always we'll have the lastUpdateID and previousUpdateID properties in the pusher update // until we finish the migration to reliable updates. So let's check it before actually updating // the properties in Onyx - if('lastUpdateID' in pushJSON && 'previousUpdateID' in pushJSON) { + if ('lastUpdateID' in pushJSON && 'previousUpdateID' in pushJSON) { console.debug('[OnyxUpdates] Received lastUpdateID from pusher', pushJSON.lastUpdateID); console.debug('[OnyxUpdates] Received previousUpdateID from pusher', pushJSON.previousUpdateID); // Store these values in Onyx to allow App.reconnectApp() to fetch incremental updates from the server when a previous session is being reconnected to. From 1f83bf559ea976d0c0f5cdcf4ee915b87dd06f3d Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Mon, 7 Aug 2023 16:27:31 +0200 Subject: [PATCH 20/20] addressign comments --- src/libs/Navigation/AppNavigator/AuthScreens.js | 3 ++- src/libs/actions/User.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.js b/src/libs/Navigation/AppNavigator/AuthScreens.js index 00431dab8887..ddd61da272e6 100644 --- a/src/libs/Navigation/AppNavigator/AuthScreens.js +++ b/src/libs/Navigation/AppNavigator/AuthScreens.js @@ -131,7 +131,8 @@ class AuthScreens extends React.Component { }); // If we are on this screen then we are "logged in", but the user might not have "just logged in". They could be reopening the app - // or returning from background. If so, we'll assume they have some app data already and we can call openApp(true) instead of openApp(). + // or returning from background. If so, we'll assume they have some app data already and we can call + // reconnectApp(onyxUpdatesLastUpdateID) instead of openApp(). // Note: If a Guide has enabled the memory only key mode then we do want to run OpenApp as their app will not be rehydrated with // the correct state on refresh. They are explicitly opting out of storing data they would need (i.e. reports_) to take advantage of // the optimizations performed during ReconnectApp. diff --git a/src/libs/actions/User.js b/src/libs/actions/User.js index 224e8a461fbb..d07cb23c039c 100644 --- a/src/libs/actions/User.js +++ b/src/libs/actions/User.js @@ -557,7 +557,7 @@ function subscribeToUserEvents() { // Not always we'll have the lastUpdateID and previousUpdateID properties in the pusher update // until we finish the migration to reliable updates. So let's check it before actually updating // the properties in Onyx - if ('lastUpdateID' in pushJSON && 'previousUpdateID' in pushJSON) { + if (pushJSON.lastUpdateID && pushJSON.previousUpdateID) { console.debug('[OnyxUpdates] Received lastUpdateID from pusher', pushJSON.lastUpdateID); console.debug('[OnyxUpdates] Received previousUpdateID from pusher', pushJSON.previousUpdateID); // Store these values in Onyx to allow App.reconnectApp() to fetch incremental updates from the server when a previous session is being reconnected to.