Scan recent commits for likely bugs (#1480)

This commit is contained in:
Elie Habib
2026-03-12 12:38:09 +04:00
committed by GitHub
parent a581253d31
commit 41faeea4b3
2 changed files with 8 additions and 6 deletions

View File

@@ -41,11 +41,14 @@ function startSweepIfNeeded(): void {
}
}
function evictLRU(): void {
// Collect keys to evict first, then delete (avoids mutating Map during iteration)
function evictLRU(incomingSize = 0): void {
// Collect keys to evict first, then delete (avoids mutating Map during iteration).
// Ensure headroom for an incoming write, not only current occupancy.
const keysToEvict: string[] = [];
for (const [k, entry] of store) {
if (store.size - keysToEvict.length < MAX_ENTRIES && totalBytes <= MAX_BYTES) break;
const nextEntryCount = store.size - keysToEvict.length + 1;
const nextTotalBytes = totalBytes + incomingSize;
if (nextEntryCount <= MAX_ENTRIES && nextTotalBytes <= MAX_BYTES) break;
keysToEvict.push(k);
totalBytes -= entry.size;
}
@@ -92,7 +95,7 @@ export function sidecarCacheSet(key: string, value: unknown, ttlSeconds: number)
// Evict if needed
if (store.size >= MAX_ENTRIES || totalBytes + size > MAX_BYTES) {
evictLRU();
evictLRU(size);
}
store.set(key, {
@@ -108,4 +111,3 @@ export function sidecarCacheSet(key: string, value: unknown, ttlSeconds: number)
export function sidecarCacheStats(): { entries: number; bytes: number; hits: number; misses: number } {
return { entries: store.size, bytes: totalBytes, hits: hitCount, misses: missCount };
}

View File

@@ -119,7 +119,7 @@ export class App {
if (panel) primeTask('stablecoins', () => panel.fetchData());
}
if (shouldPrime('telegram-intel')) {
primeTask('telegramIntel', () => this.dataLoader.loadTelegramIntel());
primeTask('telegram-intel', () => this.dataLoader.loadTelegramIntel());
}
if (shouldPrime('gulf-economies')) {
const panel = this.state.panels['gulf-economies'] as GulfEconomiesPanel | undefined;