add related hashtag pruning to maintenance worker
Build Images and Deploy / Update-PROD-Stack (push) Successful in 1m23s

This commit is contained in:
2026-03-22 00:55:21 -04:00
parent 72885ed0b0
commit d68bc99817
+17
View File
@@ -304,6 +304,23 @@ const maintenanceWorker = new Worker(
console.log(
`[maintenance] pruned snapshots — fund NAV: ${deletedFundNav.count} rows, user portfolio: ${deletedUserPortfolio.count} rows (>7d)`,
)
// ── Related hashtag pruning ────────────────────────────────────────────
// 1. Null-target records: the related hashtag was deleted (onDelete: SetNull)
// or was never tracked. Delete unconditionally — the upsert in the price
// worker will recreate them if the co-occurrence is seen again.
// 2. Weak associations: low co-occurrence records that were never reinforced,
// pruned after 30 days of inactivity.
const relatedCutoff = new Date(now.getTime() - 30 * 24 * 60 * 60 * 1000)
const [deletedNullTarget, deletedWeak] = await Promise.all([
prisma.relatedHashtag.deleteMany({ where: { relatedId: null } }),
prisma.relatedHashtag.deleteMany({
where: { relatedId: { not: null }, coOccurrences: { lt: 5 }, updatedAt: { lt: relatedCutoff } },
}),
])
console.log(
`[maintenance] pruned relatedHashtag — ${deletedNullTarget.count} null-target, ${deletedWeak.count} weak (>30d, <5 co-occurrences)`,
)
},
{ connection: redisOpts() },
)