Skip to content

Commit

Permalink
Merge pull request #92 from kidroca/kidroca/perf-set-avoid-duplicates
Browse files Browse the repository at this point in the history
perf: Skip a write to storage when nothing is actually changing
  • Loading branch information
marcaaron authored Jul 29, 2021
2 parents 61e6888 + 908ec0a commit d73900b
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 d73900b

Please sign in to comment.