MCPcopy Create free account
hub / github.com/coder/coder / cleanupLatencies

Function cleanupLatencies

site/src/contexts/useProxyLatency.ts:303–323  ·  view source on GitHub ↗
(
	stored: Record<string, ProxyLatencyReport[]>,
	regions: readonly Region[],
	now: Date,
	maxStored: number,
)

Source from the content-addressed store, hash-verified

301};
302
303const cleanupLatencies = (
304 stored: Record<string, ProxyLatencyReport[]>,
305 regions: readonly Region[],
306 now: Date,
307 maxStored: number,
308): Record<string, ProxyLatencyReport[]> => {
309 for (const [proxyId, reports] of Object.entries(stored)) {
310 if (!regions.find((region) => region.id === proxyId)) {
311 delete stored[proxyId];
312 continue;
313 }
314 const nowMS = now.getTime();
315 stored[proxyId] = reports.filter((report) => {
316 // Only keep the reports that are less then 1 week old.
317 return new Date(report.at).getTime() > nowMS - 1000 * 60 * 60 * 24 * 7;
318 });
319 // Only keep the 5 latest
320 stored[proxyId] = stored[proxyId].slice(-1 * maxStored);
321 }
322 return stored;
323};

Callers 1

Calls 2

findMethod · 0.80
filterMethod · 0.80

Tested by

no test coverage detected