From d44ba8a0aee3f93802905a3bbb1dada481349fdc Mon Sep 17 00:00:00 2001 From: alikia2x Date: Thu, 27 Mar 2025 02:13:33 +0800 Subject: [PATCH] fix: incorrect offset calculation in adjustSnapshotTime --- lib/db/snapshotSchedule.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/db/snapshotSchedule.ts b/lib/db/snapshotSchedule.ts index 04bbe6e..8c825b7 100644 --- a/lib/db/snapshotSchedule.ts +++ b/lib/db/snapshotSchedule.ts @@ -202,9 +202,9 @@ export async function adjustSnapshotTime( redisClient: Redis, ): Promise { const currentWindow = getCurrentWindowIndex(); - const targetOffset = Math.floor((expectedStartTime.getTime() - Date.now()) / (5 * MINUTE)); + const targetOffset = Math.floor((expectedStartTime.getTime() - Date.now()) / (5 * MINUTE)) - 6; - let initialOffset = 0; + let initialOffset = currentWindow + Math.max(targetOffset, 0); if (lastAvailableWindow && lastAvailableWindow.count < allowedCounts) { initialOffset = Math.max(lastAvailableWindow.offset - 2, 0); @@ -213,7 +213,7 @@ export async function adjustSnapshotTime( let timePerIteration = 0; const t = performance.now(); for (let i = initialOffset; i < WINDOW_SIZE; i++) { - const offset = (currentWindow + targetOffset + i) % WINDOW_SIZE; + const offset = i; const count = await getWindowCount(redisClient, offset); if (count < allowedCounts) {