mirror of
https://github.com/hellodigua/ChatLab.git
synced 2026-10-26 02:04:37 +08:00
feat(import): auto-generate session index after all import paths
Session index (segment/message_context tables) was previously generated inconsistently: CLI used postImportHook, Desktop relied on a separate explicit RPC call, and the CLI sync/pull legacy importer never built it. Move generateSessionIndex / generateIncrementalSessionIndex into the shared importers (streaming-importer.ts, incremental-importer.ts) so every caller gets it automatically. Remove the now-redundant calls from CLI's postImportHook. Also add the calls to the legacy importer.ts used by CLI sync/pull, which had no session index at all. Incremental imports use generateIncrementalSessionIndex, which preserves existing AI summaries. Full imports call generateSessionIndex only on newly created sessions where no summaries exist. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
2b0013f615
commit
ced4ed16bd
4 files changed
+38
-18
No files matched your search
@@ -9,7 +9,7 @@
|
||||
*/
|
||||
|
||||
import type { DatabaseAdapter } from '@openchatlab/core'
|
||||
import { generateMessageKey } from '@openchatlab/core'
|
||||
import { generateMessageKey, generateIncrementalSessionIndex } from '@openchatlab/core'
|
||||
import { streamParseFile, detectFormat, type ParseProgress } from '@openchatlab/parser'
|
||||
import { insertFtsEntries, hasFtsTable } from '../fts'
|
||||
import type { ImportProgressCallback } from './streaming-importer'
|
||||
@@ -379,6 +379,15 @@ export async function incrementalImport(
|
||||
}
|
||||
}
|
||||
|
||||
// Incremental session index (segment / message_context tables)
|
||||
if (newMessageCount > 0) {
|
||||
try {
|
||||
generateIncrementalSessionIndex(db)
|
||||
} catch {
|
||||
/* non-fatal */
|
||||
}
|
||||
}
|
||||
|
||||
const sessionStats = db
|
||||
.prepare(
|
||||
`SELECT
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
*/
|
||||
|
||||
import type { DatabaseAdapter } from '@openchatlab/core'
|
||||
import { CHAT_DB_INDEXES } from '@openchatlab/core'
|
||||
import { CHAT_DB_INDEXES, generateSessionIndex } from '@openchatlab/core'
|
||||
import type { ParsedMember, ParsedMessage } from '@openchatlab/shared-types'
|
||||
import {
|
||||
streamParseFile,
|
||||
@@ -518,6 +518,14 @@ async function streamImportSingle(
|
||||
doCheckpoint()
|
||||
logger?.perf('WAL checkpoint done', totalMessageCount)
|
||||
|
||||
// Build session index (segment / message_context tables)
|
||||
try {
|
||||
generateSessionIndex(db)
|
||||
logger?.perf('Session index built', totalMessageCount)
|
||||
} catch {
|
||||
/* non-fatal */
|
||||
}
|
||||
|
||||
// Post-import hook (e.g. overview cache)
|
||||
try {
|
||||
await deps.postImportHook?.(db, sessionId)
|
||||
|
||||
Reference in new issue
Block a user