Skip to content

Commit ab46528

Browse files
committed
Merge remote-tracking branch 'origin/main' into bugfix/reassure-flakiness
2 parents bc968d0 + 7dfedfa commit ab46528

3 files changed

Lines changed: 12 additions & 7 deletions

File tree

lib/OnyxCache.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class OnyxCache {
4747
private evictionBlocklist: Record<OnyxKey, string[] | undefined> = {};
4848

4949
/** List of keys that have been directly subscribed to or recently modified from least to most recent */
50-
private recentlyAccessedKeys: OnyxKey[] = [];
50+
private recentlyAccessedKeys = new Set<OnyxKey>();
5151

5252
constructor() {
5353
this.storageKeys = new Set();
@@ -312,7 +312,7 @@ class OnyxCache {
312312
* Remove a key from the recently accessed key list.
313313
*/
314314
removeLastAccessedKey(key: OnyxKey): void {
315-
this.recentlyAccessedKeys = this.recentlyAccessedKeys.filter((recentlyAccessedKey) => recentlyAccessedKey !== key);
315+
this.recentlyAccessedKeys.delete(key);
316316
}
317317

318318
/**
@@ -327,7 +327,7 @@ class OnyxCache {
327327
}
328328

329329
this.removeLastAccessedKey(key);
330-
this.recentlyAccessedKeys.push(key);
330+
this.recentlyAccessedKeys.add(key);
331331
}
332332

333333
/**
@@ -356,7 +356,12 @@ class OnyxCache {
356356
* Finds a key that can be safely evicted
357357
*/
358358
getKeyForEviction(): OnyxKey | undefined {
359-
return this.recentlyAccessedKeys.find((key) => !this.evictionBlocklist[key]);
359+
for (const key of this.recentlyAccessedKeys) {
360+
if (!this.evictionBlocklist[key]) {
361+
return key;
362+
}
363+
}
364+
return undefined;
360365
}
361366
}
362367

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-onyx",
3-
"version": "2.0.110",
3+
"version": "2.0.111",
44
"author": "Expensify, Inc.",
55
"homepage": "https://expensify.com",
66
"description": "State management for React Native",

0 commit comments

Comments
 (0)