Skip to content

Commit

Permalink
perf: add method for setAllKeys
Browse files Browse the repository at this point in the history
  • Loading branch information
hurali97 committed Mar 8, 2024
1 parent b4d0615 commit 1ec38d2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Onyx.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ function getAllKeys() {

// Otherwise retrieve the keys from storage and capture a promise to aid concurrent usages
const promise = Storage.getAllKeys().then((keys) => {
_.each(keys, (key) => cache.addKey(key));
cache.setAllKeys(keys);
return keys;
});

Expand Down
16 changes: 16 additions & 0 deletions lib/OnyxCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class OnyxCache {
'captureTask',
'removeLeastRecentlyUsedKeys',
'setRecentKeysLimit',
'setAllKeys',
);
}

Expand Down Expand Up @@ -116,6 +117,21 @@ class OnyxCache {
mergedKeys.forEach((key) => this.addToAccessedKeys(key));
}

/**
* Allows to set all the keys at once.
* This is useful when we are getting
* all the keys from the storage provider
* and we want to keep the cache in sync.
*
* Previously, we had to call `addKey` in a loop
* to achieve the same result.
*
* @param keys - an array of keys
*/
setAllKeys(keys: Key[]) {
this.storageKeys = new Set([...keys]);
}

/**
* Check whether the given task is already running
* @param taskName - unique name given for the task
Expand Down

0 comments on commit 1ec38d2

Please sign in to comment.