mirror of
https://github.com/AgentSeal/codeburn.git
synced 2026-05-07 22:18:08 +00:00
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.
This commit is contained in:
parent
70931b7269
commit
dacebd6d3c
1 changed files with 5 additions and 8 deletions
|
|
@ -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<string>, 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<BubbleRow>(BUBBLE_QUERY_INCREMENTAL, [afterTimestamp])
|
||||
: db.query<BubbleRow>(BUBBLE_QUERY_FULL)
|
||||
rows = db.query<BubbleRow>(BUBBLE_QUERY_SINCE, [timeFloor])
|
||||
} catch {
|
||||
return { calls: results, maxCreatedAt }
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue