(db: DatabaseAdapter)
| 402 | * Session index statistics: count, existence flag, and gap threshold from meta. |
| 403 | */ |
| 404 | export function getSessionIndexStats(db: DatabaseAdapter): SessionIndexStats { |
| 405 | let sessionCount = 0 |
| 406 | if (hasTable(db, 'segment')) { |
| 407 | try { |
| 408 | const row = db.prepare('SELECT COUNT(*) as count FROM segment').get() as { count: number } | undefined |
| 409 | sessionCount = row?.count ?? 0 |
| 410 | } catch { |
| 411 | /* table may not exist */ |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | let gapThreshold = DEFAULT_SESSION_GAP_THRESHOLD |
| 416 | try { |
| 417 | const meta = db.prepare('SELECT session_gap_threshold FROM meta LIMIT 1').get() as |
| 418 | | { session_gap_threshold: number | null } |
| 419 | | undefined |
| 420 | if (meta?.session_gap_threshold) { |
| 421 | gapThreshold = meta.session_gap_threshold |
| 422 | } |
| 423 | } catch { |
| 424 | /* column may not exist */ |
| 425 | } |
| 426 | |
| 427 | return { sessionCount, hasIndex: sessionCount > 0, gapThreshold } |
| 428 | } |
| 429 | |
| 430 | /** |
| 431 | * Query chat sessions within a time range. |
no test coverage detected