Skip to content

Commit

Permalink
NetworkRequestQueue: add request filter/compare logic
Browse files Browse the repository at this point in the history
Use _.isEqual to skip adding requests that we might already have persisted
and the same when removing to remove only the matching request
  • Loading branch information
kidroca committed Dec 1, 2021
1 parent 6a61ea1 commit 5cd8b4a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/libs/actions/NetworkRequestQueue.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import Onyx from 'react-native-onyx';
import _ from 'underscore';
import lodashUnionWith from 'lodash/unionWith';
import ONYXKEYS from '../../ONYXKEYS';

const retryMap = new Map();
Expand All @@ -15,12 +17,14 @@ function clearPersistedRequests() {
}

function saveRetryableRequests(retryableRequests) {
Onyx.merge(ONYXKEYS.NETWORK_REQUEST_QUEUE, retryableRequests);
const requests = lodashUnionWith(persistedRequests, retryableRequests, _.isEqual);
Onyx.set(ONYXKEYS.NETWORK_REQUEST_QUEUE, requests);
}

function removeRetryableRequest(request) {
retryMap.delete(request);
console.debug('Remove from storage: ', {request});
const remaining = _.reject(persistedRequests, r => _.isEqual(r, request));
Onyx.set(ONYXKEYS.NETWORK_REQUEST_QUEUE, remaining);
}

function incrementRetries(request) {
Expand Down

0 comments on commit 5cd8b4a

Please sign in to comment.