( stored: Record<string, ProxyLatencyReport[]>, regions: readonly Region[], now: Date, maxStored: number, )
| 301 | }; |
| 302 | |
| 303 | const 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 | }; |
no test coverage detected