From dacebd6d3c69b56fe2fdbd1358a13c2d698a660a Mon Sep 17 00:00:00 2001 From: AgentSeal Date: Wed, 15 Apr 2026 03:51:11 -0700 Subject: [PATCH] perf: add 90-day time floor to Cursor SQL query Instead of scanning all 300K+ rows on every load, only query entries from the last 90 days. Eliminates the full table scan that caused slow provider switching on large databases. --- src/providers/cursor.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/providers/cursor.ts b/src/providers/cursor.ts index 39c6d5e..4a980d6 100644 --- a/src/providers/cursor.ts +++ b/src/providers/cursor.ts @@ -64,11 +64,7 @@ const BUBBLE_QUERY_BASE = ` AND json_extract(value, '$.tokenCount.inputTokens') > 0 ` -const BUBBLE_QUERY_FULL = BUBBLE_QUERY_BASE + ` - ORDER BY json_extract(value, '$.createdAt') ASC -` - -const BUBBLE_QUERY_INCREMENTAL = BUBBLE_QUERY_BASE + ` +const BUBBLE_QUERY_SINCE = BUBBLE_QUERY_BASE + ` AND json_extract(value, '$.createdAt') > ? ORDER BY json_extract(value, '$.createdAt') ASC ` @@ -89,11 +85,12 @@ function parseBubbles(db: SqliteDatabase, seenKeys: Set, afterTimestamp? let skipped = 0 let maxCreatedAt = afterTimestamp ?? 0 + const DEFAULT_LOOKBACK_MS = 90 * 24 * 60 * 60 * 1000 + const timeFloor = afterTimestamp ?? (Date.now() - DEFAULT_LOOKBACK_MS) + let rows: BubbleRow[] try { - rows = afterTimestamp - ? db.query(BUBBLE_QUERY_INCREMENTAL, [afterTimestamp]) - : db.query(BUBBLE_QUERY_FULL) + rows = db.query(BUBBLE_QUERY_SINCE, [timeFloor]) } catch { return { calls: results, maxCreatedAt } }