Checkpoint: Purge automatique des tombstones (processed_dedup_keys) de plus de 6 mois :
- purgeOldArticles dans db.ts : suppression des entrées processedDedupKeys.processedAt <= cutoff 6 mois - Logs cron et init mis à jour pour afficher le nombre de tombstones supprimés - 0 erreur TypeScript
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
{
|
{
|
||||||
"version": "bb8a78b4",
|
"version": "509dd73b",
|
||||||
"timestamp": 1783732106605
|
"timestamp": 1783732495856
|
||||||
}
|
}
|
||||||
@@ -98,8 +98,8 @@ export async function scheduleDailyImport() {
|
|||||||
const retentionMonths = retentionStr ? parseInt(retentionStr, 10) : 0;
|
const retentionMonths = retentionStr ? parseInt(retentionStr, 10) : 0;
|
||||||
if (retentionMonths > 0) {
|
if (retentionMonths > 0) {
|
||||||
const purged = await purgeOldArticles(retentionMonths);
|
const purged = await purgeOldArticles(retentionMonths);
|
||||||
if (purged.veille > 0 || purged.aap > 0) {
|
if (purged.veille > 0 || purged.aap > 0 || purged.tombstones > 0) {
|
||||||
console.log(`[Cron] Purge rétention (${retentionMonths} mois) — Veille: -${purged.veille} | AAP: -${purged.aap}`);
|
console.log(`[Cron] Purge rétention (${retentionMonths} mois) — Veille: -${purged.veille} | AAP: -${purged.aap} | Tombstones: -${purged.tombstones}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -236,8 +236,8 @@ async function startServer() {
|
|||||||
const retentionMonths = retentionStr ? parseInt(retentionStr, 10) : 0;
|
const retentionMonths = retentionStr ? parseInt(retentionStr, 10) : 0;
|
||||||
if (retentionMonths > 0) {
|
if (retentionMonths > 0) {
|
||||||
const purged = await purgeOldArticles(retentionMonths);
|
const purged = await purgeOldArticles(retentionMonths);
|
||||||
if (purged.veille > 0 || purged.aap > 0) {
|
if (purged.veille > 0 || purged.aap > 0 || purged.tombstones > 0) {
|
||||||
console.log(`[Init] Purge rétention (${retentionMonths} mois) — Veille: -${purged.veille} | AAP: -${purged.aap}`);
|
console.log(`[Init] Purge rétention (${retentionMonths} mois) — Veille: -${purged.veille} | AAP: -${purged.aap} | Tombstones: -${purged.tombstones}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import {
|
|||||||
InsertIdea,
|
InsertIdea,
|
||||||
rssFeeds,
|
rssFeeds,
|
||||||
rssSettings,
|
rssSettings,
|
||||||
|
processedDedupKeys,
|
||||||
type InsertRssFeed,
|
type InsertRssFeed,
|
||||||
type InsertRssSettings,
|
type InsertRssSettings,
|
||||||
type ImportLog,
|
type ImportLog,
|
||||||
@@ -489,16 +490,21 @@ export async function saveRssSettings(data: Partial<Omit<InsertRssSettings, "id"
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ─── Purge ───────────────────────────────────────────────────────────────────
|
// ─── Purge ───────────────────────────────────────────────────────────────────
|
||||||
export async function purgeOldArticles(retentionMonths: number): Promise<{ veille: number; aap: number }> {
|
export async function purgeOldArticles(retentionMonths: number): Promise<{ veille: number; aap: number; tombstones: number }> {
|
||||||
const db = await getDb();
|
const db = await getDb();
|
||||||
if (!db) throw new Error("Database not available");
|
if (!db) throw new Error("Database not available");
|
||||||
const cutoff = new Date();
|
const cutoff = new Date();
|
||||||
cutoff.setMonth(cutoff.getMonth() - retentionMonths);
|
cutoff.setMonth(cutoff.getMonth() - retentionMonths);
|
||||||
const veilleResult = await db.delete(veilleItems).where(lte(veilleItems.importedAt, cutoff));
|
const veilleResult = await db.delete(veilleItems).where(lte(veilleItems.importedAt, cutoff));
|
||||||
const aapResult = await db.delete(aapItems).where(lte(aapItems.importedAt, cutoff));
|
const aapResult = await db.delete(aapItems).where(lte(aapItems.importedAt, cutoff));
|
||||||
|
// Purge des tombstones (processed_dedup_keys) de plus de 6 mois
|
||||||
|
const tombstoneCutoff = new Date();
|
||||||
|
tombstoneCutoff.setMonth(tombstoneCutoff.getMonth() - 6);
|
||||||
|
const tombstoneResult = await db.delete(processedDedupKeys).where(lte(processedDedupKeys.processedAt, tombstoneCutoff));
|
||||||
return {
|
return {
|
||||||
veille: (veilleResult as any).affectedRows ?? 0,
|
veille: (veilleResult as any).affectedRows ?? 0,
|
||||||
aap: (aapResult as any).affectedRows ?? 0,
|
aap: (aapResult as any).affectedRows ?? 0,
|
||||||
|
tombstones: (tombstoneResult as any).affectedRows ?? 0,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user