feat(fingerprint): clean up stale snapshots older than 1 year

This commit is contained in:
Varun Narravula
2026-01-20 11:48:44 -08:00
committed by Owen Schwartz
parent e2e09527ec
commit d5ae381528
2 changed files with 13 additions and 1 deletions

View File

@@ -1,7 +1,8 @@
import { sha256 } from "@oslojs/crypto/sha2";
import { encodeHexLowerCase } from "@oslojs/encoding";
import { currentFingerprint, db, fingerprintSnapshots, Olm } from "@server/db";
import { desc, eq } from "drizzle-orm";
import { calculateCutoffTimestamp } from "@server/lib/cleanupLogs";
import { desc, eq, lt } from "drizzle-orm";
function fingerprintSnapshotHash(fingerprint: any, postures: any): string {
const canonical = {
@@ -213,3 +214,11 @@ export async function handleFingerprintInsertion(
.where(eq(currentFingerprint.fingerprintId, current.fingerprintId));
}
}
export async function cleanUpOldFingerprintSnapshots(retentionDays: number) {
const cutoff = calculateCutoffTimestamp(retentionDays);
await db
.delete(fingerprintSnapshots)
.where(lt(fingerprintSnapshots.collectedAt, cutoff));
}