Skip to content

Commit

Permalink
perf: Don't remove default keys from cache
Browse files Browse the repository at this point in the history
  • Loading branch information
kidroca committed Jul 14, 2021
1 parent d6e05e7 commit 93c30be
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions lib/Onyx.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,12 +411,14 @@ function cleanCache() {
/* Keep any other items with active connections
* Note: after `splice` the array no longer contains the `mostRecent` */
const stillConnected = recentlyAccessedKeys.filter((key) => {
const hasRemainingConnections = _.some(callbackToStateMapping, mapping => key.startsWith(mapping.key));
if (!hasRemainingConnections) {
const shouldKeep = _.has(defaultKeyStates, key)
|| _.some(callbackToStateMapping, mapping => key.startsWith(mapping.key));

if (!shouldKeep) {
cache.drop(key);
}

return hasRemainingConnections;
return shouldKeep;
});

recentlyAccessedKeys = stillConnected.concat(mostRecent);
Expand Down Expand Up @@ -616,7 +618,7 @@ function merge(key, val) {
}

/**
* Merge user provided default key value pairs.
* Merge stored data and user provided default key value pairs to cache
*
* @returns {Promise<void>}
*/
Expand All @@ -643,12 +645,13 @@ function clear() {
return getAllKeys()
.then((keys) => {
_.each(keys, (key) => {
keyChanged(key, null);
cache.set(key, null);
if (!_.has(defaultKeyStates, key)) {
keyChanged(key, null);
cache.set(key, null);
}
});
})
.then(AsyncStorage.clear)
.then(initializeWithDefaultKeyStates);
.then(AsyncStorage.clear);
}

/**
Expand Down

0 comments on commit 93c30be

Please sign in to comment.