From 908ec0a25cad0727332b9d4a4261c4f41773038e Mon Sep 17 00:00:00 2001 From: Peter Velkov Date: Tue, 13 Jul 2021 20:58:31 +0300 Subject: [PATCH] perf: Skip a write to storage when nothing is actually changing This covers both `set` and `merge` --- lib/Onyx.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/Onyx.js b/lib/Onyx.js index 6b662d5f..1e69e44a 100644 --- a/lib/Onyx.js +++ b/lib/Onyx.js @@ -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);