From b9b57229d86493daf4a9d246eaecbf98f7e1553c Mon Sep 17 00:00:00 2001 From: tienifr Date: Tue, 10 Oct 2023 01:54:24 +0700 Subject: [PATCH 1/2] use optional chaining --- src/libs/Middleware/HandleUnusedOptimisticID.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/libs/Middleware/HandleUnusedOptimisticID.ts b/src/libs/Middleware/HandleUnusedOptimisticID.ts index a96eb4d5651..14f7d08d1fd 100644 --- a/src/libs/Middleware/HandleUnusedOptimisticID.ts +++ b/src/libs/Middleware/HandleUnusedOptimisticID.ts @@ -10,11 +10,7 @@ const handleUnusedOptimisticID: Middleware = (requestResponse, request, isFromSe const responseOnyxData = response?.onyxData ?? []; responseOnyxData.forEach((onyxData) => { const key = onyxData.key; - if (!key) { - return; - } - - if (!key.startsWith(ONYXKEYS.COLLECTION.REPORT)) { + if (!key?.startsWith(ONYXKEYS.COLLECTION.REPORT)) { return; } From 9a6f29d95138ed63274900d40b6b9bbde0e605a1 Mon Sep 17 00:00:00 2001 From: tienifr Date: Tue, 10 Oct 2023 01:54:36 +0700 Subject: [PATCH 2/2] remove catch error --- src/libs/Middleware/SaveResponseInOnyx.js | 76 +++++++++++------------ 1 file changed, 36 insertions(+), 40 deletions(-) diff --git a/src/libs/Middleware/SaveResponseInOnyx.js b/src/libs/Middleware/SaveResponseInOnyx.js index c866a797877..d8c47d4c01d 100644 --- a/src/libs/Middleware/SaveResponseInOnyx.js +++ b/src/libs/Middleware/SaveResponseInOnyx.js @@ -14,50 +14,46 @@ const requestsToIgnoreLastUpdateID = ['OpenApp', 'ReconnectApp', 'GetMissingOnyx * @returns {Promise} */ function SaveResponseInOnyx(requestResponse, request) { - return requestResponse - .then((response = {}) => { - const onyxUpdates = response.onyxData; - - // Sometimes we call requests that are successfull but they don't have any response or any success/failure data to set. Let's return early since - // we don't need to store anything here. - if (!onyxUpdates && !request.successData && !request.failureData) { - return Promise.resolve(response); + return requestResponse.then((response = {}) => { + const onyxUpdates = response.onyxData; + + // Sometimes we call requests that are successfull but they don't have any response or any success/failure data to set. Let's return early since + // we don't need to store anything here. + if (!onyxUpdates && !request.successData && !request.failureData) { + return Promise.resolve(response); + } + + // 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 false; } - // 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 false; - } - - MemoryOnlyKeys.enable(); - return true; - }); - - const responseToApply = { - type: CONST.ONYX_UPDATE_TYPES.HTTPS, - lastUpdateID: Number(response.lastUpdateID || 0), - previousUpdateID: Number(response.previousUpdateID || 0), - request, - response, - }; - - if (_.includes(requestsToIgnoreLastUpdateID, request.command) || !OnyxUpdates.doesClientNeedToBeUpdated(Number(response.previousUpdateID || 0))) { - return OnyxUpdates.apply(responseToApply); - } + 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 - OnyxUpdates.saveUpdateInformation(responseToApply); - - // Ensure the queue is paused while the client resolves the gap in onyx updates so that updates are guaranteed to happen in a specific order. - return Promise.resolve({ - ...response, - shouldPauseQueue: true, - }); - }) - .catch((err) => { - console.error('Got exception while saving response in Onyx', err); + const responseToApply = { + type: CONST.ONYX_UPDATE_TYPES.HTTPS, + lastUpdateID: Number(response.lastUpdateID || 0), + previousUpdateID: Number(response.previousUpdateID || 0), + request, + response, + }; + + if (_.includes(requestsToIgnoreLastUpdateID, request.command) || !OnyxUpdates.doesClientNeedToBeUpdated(Number(response.previousUpdateID || 0))) { + return OnyxUpdates.apply(responseToApply); + } + + // 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.saveUpdateInformation(responseToApply); + + // Ensure the queue is paused while the client resolves the gap in onyx updates so that updates are guaranteed to happen in a specific order. + return Promise.resolve({ + ...response, + shouldPauseQueue: true, }); + }); } export default SaveResponseInOnyx;