From 7337538f0be8148c79923e0a1463b270b2fe6b39 Mon Sep 17 00:00:00 2001 From: alikia2x Date: Thu, 27 Mar 2025 05:49:19 +0800 Subject: [PATCH] fix: snapshotBefore may returns null even there's a snapshot exists --- lib/mq/exec/snapshotTick.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/mq/exec/snapshotTick.ts b/lib/mq/exec/snapshotTick.ts index 319a20c..b18d845 100644 --- a/lib/mq/exec/snapshotTick.ts +++ b/lib/mq/exec/snapshotTick.ts @@ -173,7 +173,8 @@ export const collectMilestoneSnapshotsWorker = async (_job: Job) => { const getRegularSnapshotInterval = async (client: Client, aid: number) => { const now = Date.now(); const date = new Date(now - 24 * HOUR); - const oldSnapshot = await findSnapshotBefore(client, aid, date); + let oldSnapshot = await findSnapshotBefore(client, aid, date); + if (!oldSnapshot) oldSnapshot = await findClosestSnapshot(client, aid, date); const latestSnapshot = await getLatestSnapshot(client, aid); if (!oldSnapshot || !latestSnapshot) return 0; if (oldSnapshot.created_at === latestSnapshot.created_at) return 0; @@ -181,7 +182,7 @@ const getRegularSnapshotInterval = async (client: Client, aid: number) => { if (hoursDiff < 8) return 24; const viewsDiff = latestSnapshot.views - oldSnapshot.views; if (viewsDiff === 0) return 72; - const speedPerDay = viewsDiff / hoursDiff * 24; + const speedPerDay = viewsDiff / (hoursDiff + 0.001) * 24; if (speedPerDay < 6) return 36; if (speedPerDay < 120) return 24; if (speedPerDay < 320) return 12;