Skip to content

Commit

Permalink
perf: Skip a write to storage when nothing is actually changing
Browse files Browse the repository at this point in the history
This covers both `set` and `merge`
  • Loading branch information
kidroca committed Jul 27, 2021
1 parent 9549e40 commit 908ec0a
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/Onyx.js
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,11 @@ function evictStorageAndRetry(error, ionMethod, ...args) {
* @returns {Promise}
*/
function set(key, val) {
// Skip writing to storage if the value hasn't changed
if (cache.hasCacheForKey(key) && _.isEqual(val, cache.getValue(key))) {
return Promise.resolve();
}

// Adds the key to cache when it's not available
cache.set(key, val);

Expand Down

0 comments on commit 908ec0a

Please sign in to comment.