mirror of
https://github.com/chillpadclub/bedolaga-cabinet.git
synced 2026-07-28 17:43:47 +00:00
fix: plug memory leaks in blob URLs and traffic cache
- Add URL.revokeObjectURL on unmount and media removal in AdminBroadcastCreate, AdminPinnedMessageCreate, Support - Track blob URLs via refs to revoke before creating new ones - Add clearCreateAttachment/clearReplyAttachment helpers in Support to properly revoke blob URLs when clearing attachments - Cap adminTraffic cache at 20 entries with FIFO eviction to prevent unbounded memory growth from different filter combinations
This commit is contained in:
@@ -63,6 +63,7 @@ export type TrafficParams = {
|
||||
};
|
||||
|
||||
const CACHE_TTL = 5 * 60 * 1000; // 5 minutes
|
||||
const MAX_CACHE_ENTRIES = 20;
|
||||
|
||||
const trafficCache = new Map<string, { data: TrafficUsageResponse; timestamp: number }>();
|
||||
|
||||
@@ -106,6 +107,16 @@ export const adminTrafficApi = {
|
||||
|
||||
trafficCache.set(key, { data, timestamp: Date.now() });
|
||||
|
||||
// Evict oldest entries to prevent unbounded memory growth
|
||||
if (trafficCache.size > MAX_CACHE_ENTRIES) {
|
||||
const iterator = trafficCache.keys();
|
||||
while (trafficCache.size > MAX_CACHE_ENTRIES) {
|
||||
const oldest = iterator.next();
|
||||
if (oldest.done) break;
|
||||
trafficCache.delete(oldest.value);
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user