Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/Onyx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ function init({
OnyxUtils.initStoreValues(keys, initialKeyStates, evictableKeys);

// Initialize all of our keys with data provided then give green light to any pending connections
Promise.all([cache.addEvictableKeysToRecentlyAccessedList(OnyxUtils.isCollectionKey), OnyxUtils.initializeWithDefaultKeyStates()]).then(OnyxUtils.getDeferredInitTask().resolve);
Promise.all([cache.addEvictableKeysToRecentlyAccessedList(OnyxUtils.isCollectionKey, OnyxUtils.getAllKeys), OnyxUtils.initializeWithDefaultKeyStates()]).then(
OnyxUtils.getDeferredInitTask().resolve,
);
}

/**
Expand Down
9 changes: 5 additions & 4 deletions lib/OnyxCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import bindAll from 'lodash/bindAll';
import type {ValueOf} from 'type-fest';
import utils from './utils';
import type {OnyxKey, OnyxValue} from './types';
import Storage from './storage';
import * as Str from './Str';

// Task constants
Expand Down Expand Up @@ -336,11 +335,13 @@ class OnyxCache {
* the recently accessed list when initializing the app. This
* enables keys that have not recently been accessed to be
* removed.
* @param isCollectionKeyFn - Function to determine if a key is a collection key
* @param getAllKeysFn - Function to get all keys, defaults to Storage.getAllKeys
*/
addEvictableKeysToRecentlyAccessedList(isCollectionKeyFn: (key: OnyxKey) => boolean): Promise<void> {
return Storage.getAllKeys().then((keys: string[]) => {
addEvictableKeysToRecentlyAccessedList(isCollectionKeyFn: (key: OnyxKey) => boolean, getAllKeysFn: () => Promise<Set<OnyxKey>>): Promise<void> {
return getAllKeysFn().then((keys: Set<OnyxKey>) => {
this.evictionAllowList.forEach((evictableKey) => {
keys.forEach((key: string) => {
keys.forEach((key: OnyxKey) => {
if (!this.isKeyMatch(evictableKey, key)) {
return;
}
Expand Down
17 changes: 12 additions & 5 deletions tests/perf-test/OnyxUtils.perf-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,12 +279,19 @@ describe('OnyxUtils', () => {
};

test('one call adding 1k keys', async () => {
await measureAsyncFunction(() => OnyxCache.addEvictableKeysToRecentlyAccessedList(() => false), {
beforeEach: async () => {
await Onyx.multiSet(data);
await measureAsyncFunction(
() =>
OnyxCache.addEvictableKeysToRecentlyAccessedList(
() => false,
() => Promise.resolve(new Set(Object.keys(data))),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kubabutkiewicz please move () => false and () => Promise.resolve(new Set(Object.keys(data))) to outside measureAsyncFunction

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fabioh8010 I am not sure what do you mean, something like that?
image

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it's okay this way!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok thanks, pushed a change

),
{
beforeEach: async () => {
await Onyx.multiSet(data);
},
afterEach: clearOnyxAfterEachMeasure,
},
afterEach: clearOnyxAfterEachMeasure,
});
);
});
});

Expand Down
Loading