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:
Fringg
2026-02-23 17:15:11 +03:00
parent 17b2f2e903
commit 7cf72735ec
4 changed files with 85 additions and 13 deletions

View File

@@ -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;
},