MCPcopy Index your code
hub / github.com/ChatLab/ChatLab / getSessionIndexStats

Function getSessionIndexStats

packages/core/src/query/session-queries.ts:404–428  ·  view source on GitHub ↗
(db: DatabaseAdapter)

Source from the content-addressed store, hash-verified

402 * Session index statistics: count, existence flag, and gap threshold from meta.
403 */
404export 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.

Callers 2

getAllIndexStatsFunction · 0.90

Calls 3

hasTableFunction · 0.90
getMethod · 0.65
prepareMethod · 0.65

Tested by

no test coverage detected