From dcc2dbb27816b934dd31e89f70087b09c10defef Mon Sep 17 00:00:00 2001 From: lyc8503 Date: Sun, 30 Jun 2024 21:54:57 +0800 Subject: [PATCH] remove old incident, keep history only for 90d --- README.md | 4 ++-- worker/src/index.ts | 22 +++++++++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 74057fd..242284c 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# 📈[UptimeFlare](https://github.com/lyc8503/UptimeFlare) +# ✔[UptimeFlare](https://github.com/lyc8503/UptimeFlare) A more advanced, serverless, and free uptime monitoring & status page solution, powered by Cloudflare Workers, complete with a user-friendly interface. @@ -44,4 +44,4 @@ Please refer to [Wiki](https://github.com/lyc8503/UptimeFlare/wiki) - [ ] SSL certificate checks - [ ] Self-host Dockerfile - [ ] Incident timeline -- [ ] Remove old incidents +- [x] Remove old incidents diff --git a/worker/src/index.ts b/worker/src/index.ts index cb79387..3fe7478 100644 --- a/worker/src/index.ts +++ b/worker/src/index.ts @@ -283,7 +283,27 @@ export default { latencyLists.all.shift() } state.latency[monitor.id] = latencyLists - // TODO: discard old incidents + + // discard old incidents + let incidentList = state.incident[monitor.id] + while (incidentList.length > 0 && incidentList[0].end && incidentList[0].end < currentTimeSecond - 90 * 24 * 60 * 60) { + incidentList.shift() + } + + if (incidentList.length == 0 || ( + incidentList[0].start[0] > currentTimeSecond - 90 * 24 * 60 * 60 && + incidentList[0].error[0] != 'dummy' + )) { + // put the dummy incident back + incidentList.unshift( + { + start: [currentTimeSecond - 90 * 24 * 60 * 60], + end: currentTimeSecond - 90 * 24 * 60 * 60, + error: ['dummy'], + } + ) + } + state.incident[monitor.id] = incidentList statusChanged ||= monitorStatusChanged }