mirror of
https://github.com/fosrl/pangolin.git
synced 2026-03-05 02:06:41 +00:00
feat(fingerprint): clean up stale snapshots older than 1 year
This commit is contained in:
committed by
Owen Schwartz
parent
e2e09527ec
commit
d5ae381528
@@ -3,6 +3,7 @@ import { cleanUpOldLogs as cleanUpOldAccessLogs } from "#dynamic/lib/logAccessAu
|
|||||||
import { cleanUpOldLogs as cleanUpOldActionLogs } from "#dynamic/middlewares/logActionAudit";
|
import { cleanUpOldLogs as cleanUpOldActionLogs } from "#dynamic/middlewares/logActionAudit";
|
||||||
import { cleanUpOldLogs as cleanUpOldRequestLogs } from "@server/routers/badger/logRequestAudit";
|
import { cleanUpOldLogs as cleanUpOldRequestLogs } from "@server/routers/badger/logRequestAudit";
|
||||||
import { gt, or } from "drizzle-orm";
|
import { gt, or } from "drizzle-orm";
|
||||||
|
import { cleanUpOldFingerprintSnapshots } from "@server/routers/olm/fingerprintingUtils";
|
||||||
|
|
||||||
export function initLogCleanupInterval() {
|
export function initLogCleanupInterval() {
|
||||||
return setInterval(
|
return setInterval(
|
||||||
@@ -56,6 +57,8 @@ export function initLogCleanupInterval() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await cleanUpOldFingerprintSnapshots(365);
|
||||||
},
|
},
|
||||||
3 * 60 * 60 * 1000
|
3 * 60 * 60 * 1000
|
||||||
); // every 3 hours
|
); // every 3 hours
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import { sha256 } from "@oslojs/crypto/sha2";
|
import { sha256 } from "@oslojs/crypto/sha2";
|
||||||
import { encodeHexLowerCase } from "@oslojs/encoding";
|
import { encodeHexLowerCase } from "@oslojs/encoding";
|
||||||
import { currentFingerprint, db, fingerprintSnapshots, Olm } from "@server/db";
|
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 {
|
function fingerprintSnapshotHash(fingerprint: any, postures: any): string {
|
||||||
const canonical = {
|
const canonical = {
|
||||||
@@ -213,3 +214,11 @@ export async function handleFingerprintInsertion(
|
|||||||
.where(eq(currentFingerprint.fingerprintId, current.fingerprintId));
|
.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));
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user