1
0

fix: incorrect type of window_start (actual: string) with postgres.js in refreshSnapshotWindowCounts

This commit is contained in:
alikia2x (寒寒) 2026-01-09 17:07:41 +08:00
parent bdc10f17a1
commit 2fc9014dfb
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG Key ID: 56209E0CCD8420C6

View File

@ -19,7 +19,7 @@ function getWindowFromDate(date: Date) {
}
export async function refreshSnapshotWindowCounts(sql: Psql, redisClient: Redis) {
const result = await sql<{ window_start: Date; count: number }[]>`
const result = await sql<{ window_start: string; count: number }[]>`
SELECT
started_at_5min_utc AT TIME ZONE 'UTC' AS window_start,
count
@ -41,7 +41,7 @@ export async function refreshSnapshotWindowCounts(sql: Psql, redisClient: Redis)
await redisClient.del(REDIS_KEY);
for (const row of result) {
await redisClient.hset(REDIS_KEY, row.window_start.toISOString(), Number(row.count));
await redisClient.hset(REDIS_KEY, new Date(row.window_start).toISOString(), Number(row.count));
}
}
@ -52,11 +52,6 @@ export async function initSnapshotWindowCounts(sql: Psql, redisClient: Redis) {
}, 5 * MINUTE);
}
async function getWindowCount(redisClient: Redis, window: Date): Promise<number> {
const count = await redisClient.hget(REDIS_KEY, window.toISOString());
return count ? parseInt(count, 10) : 0;
}
async function incrWindowCount(redisClient: Redis, window: Date) {
return redisClient.hincrby(REDIS_KEY, window.toISOString(), 1);
}