forked from jordanlambrecht/tracker-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalert-pruning.ts
More file actions
22 lines (19 loc) · 744 Bytes
/
Copy pathalert-pruning.ts
File metadata and controls
22 lines (19 loc) · 744 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// src/lib/alert-pruning.ts
import { and, inArray, lt } from "drizzle-orm"
import type { AlertType } from "@/lib/dashboard"
import { db } from "@/lib/db"
import { dismissedAlerts } from "@/lib/db/schema"
export const EXPIRING_ALERT_TYPES: AlertType[] = ["stale-data", "zero-seeding"]
export const NON_DISMISSIBLE_ALERT_TYPES = new Set<AlertType>(["client-error", "poll-paused"])
export const ALERT_EXPIRY_MS = 24 * 60 * 60 * 1000
export async function pruneDismissedAlerts(): Promise<void> {
const cutoff = new Date(Date.now() - ALERT_EXPIRY_MS)
await db
.delete(dismissedAlerts)
.where(
and(
inArray(dismissedAlerts.alertType, EXPIRING_ALERT_TYPES),
lt(dismissedAlerts.dismissedAt, cutoff)
)
)
}