From 093bc3697cbc8993ea31338ad21c2400dcef1f7f Mon Sep 17 00:00:00 2001 From: alikia2x Date: Wed, 29 Oct 2025 22:01:17 +0800 Subject: [PATCH] update: limit the range of schedule candidates for a tick --- packages/crawler/db/snapshotSchedule.ts | 7 ++----- packages/crawler/mq/task/removeAllTimeoutSchedules.ts | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/packages/crawler/db/snapshotSchedule.ts b/packages/crawler/db/snapshotSchedule.ts index f5b5e07..aad7921 100644 --- a/packages/crawler/db/snapshotSchedule.ts +++ b/packages/crawler/db/snapshotSchedule.ts @@ -276,13 +276,9 @@ export async function getSnapshotsInNextSecond(sql: Psql) { SELECT * FROM snapshot_schedule WHERE started_at <= NOW() + INTERVAL '1 seconds' + AND started_at >= NOW() - INTERVAL '1 minutes' AND status = 'pending' AND type != 'normal' - ORDER BY CASE - WHEN type = 'milestone' THEN 0 - ELSE 1 - END, - started_at LIMIT 10; `; } @@ -292,6 +288,7 @@ export async function getBulkSnapshotsInNextSecond(sql: Psql) { SELECT * FROM snapshot_schedule WHERE (started_at <= NOW() + INTERVAL '15 seconds') + AND started_at >= NOW() - INTERVAL '2 minutes' AND status = 'pending' AND (type = 'normal' OR type = 'archive') ORDER BY CASE diff --git a/packages/crawler/mq/task/removeAllTimeoutSchedules.ts b/packages/crawler/mq/task/removeAllTimeoutSchedules.ts index 06afe3d..e7700eb 100644 --- a/packages/crawler/mq/task/removeAllTimeoutSchedules.ts +++ b/packages/crawler/mq/task/removeAllTimeoutSchedules.ts @@ -11,7 +11,7 @@ export async function removeAllTimeoutSchedules() { WITH deleted AS ( DELETE FROM snapshot_schedule WHERE status IN ('pending', 'processing') - AND started_at < NOW() - INTERVAL '30 minutes' + AND started_at < NOW() - INTERVAL '2 minute' RETURNING * ) SELECT count(*) FROM deleted;