From cb573e55d9d97e1e502a3987cfa098242b9defee Mon Sep 17 00:00:00 2001 From: alikia2x Date: Mon, 24 Mar 2025 04:01:44 +0800 Subject: [PATCH] fix: incorrect offset when initializing --- lib/db/snapshotSchedule.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/db/snapshotSchedule.ts b/lib/db/snapshotSchedule.ts index bc8a039..4b0829e 100644 --- a/lib/db/snapshotSchedule.ts +++ b/lib/db/snapshotSchedule.ts @@ -35,8 +35,11 @@ export async function refreshSnapshotWindowCounts(client: Client, redisClient: R await redisClient.del(REDIS_KEY); + const currentWindow = getCurrentWindowIndex(); + for (const row of result.rows) { - const offset = Math.floor((row.window_start.getTime() - startTime) / (5 * MINUTE)); + const targetOffset = Math.floor((row.window_start.getTime() - startTime) / (5 * MINUTE)); + const offset = (currentWindow + targetOffset) % WINDOW_SIZE; if (offset >= 0 && offset < WINDOW_SIZE) { await redisClient.hset(REDIS_KEY, offset.toString(), Number(row.count)); }