Skip to content
Merged
Changes from all commits
Commits
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
13 changes: 9 additions & 4 deletions lib/OnyxCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class OnyxCache {
private evictionBlocklist: Record<OnyxKey, string[] | undefined> = {};

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

constructor() {
this.storageKeys = new Set();
Expand Down Expand Up @@ -312,7 +312,7 @@ class OnyxCache {
* Remove a key from the recently accessed key list.
*/
removeLastAccessedKey(key: OnyxKey): void {
this.recentlyAccessedKeys = this.recentlyAccessedKeys.filter((recentlyAccessedKey) => recentlyAccessedKey !== key);
this.recentlyAccessedKeys.delete(key);
}

/**
Expand All @@ -327,7 +327,7 @@ class OnyxCache {
}

this.removeLastAccessedKey(key);
this.recentlyAccessedKeys.push(key);
this.recentlyAccessedKeys.add(key);
}

/**
Expand Down Expand Up @@ -356,7 +356,12 @@ class OnyxCache {
* Finds a key that can be safely evicted
*/
getKeyForEviction(): OnyxKey | undefined {
return this.recentlyAccessedKeys.find((key) => !this.evictionBlocklist[key]);
for (const key of this.recentlyAccessedKeys) {
if (!this.evictionBlocklist[key]) {
return key;
}
}
return undefined;
}
}

Expand Down
Loading