mirror of
https://github.com/hellodigua/ChatLab.git
synced 2026-10-25 17:54:34 +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
@@ -8,7 +8,14 @@
|
||||
import * as fs from 'fs'
|
||||
import * as crypto from 'crypto'
|
||||
import type { DatabaseAdapter } from '@openchatlab/core'
|
||||
import { CHAT_DB_SCHEMA, FTS_TABLE_SCHEMA, generateMessageKey, buildMemberIdMap } from '@openchatlab/core'
|
||||
import {
|
||||
CHAT_DB_SCHEMA,
|
||||
FTS_TABLE_SCHEMA,
|
||||
generateMessageKey,
|
||||
buildMemberIdMap,
|
||||
generateSessionIndex,
|
||||
generateIncrementalSessionIndex,
|
||||
} from '@openchatlab/core'
|
||||
import type { DatabaseManager } from '@openchatlab/node-runtime'
|
||||
import { writeParseResultToDb } from '@openchatlab/node-runtime'
|
||||
import type { ParsedData, ImportMessage } from './chatlab-reader'
|
||||
@@ -51,6 +58,12 @@ function fullImport(
|
||||
|
||||
buildFts(db, onProgress)
|
||||
|
||||
try {
|
||||
generateSessionIndex(db)
|
||||
} catch {
|
||||
/* non-fatal */
|
||||
}
|
||||
|
||||
return { messageCount: stats.messageCount, memberCount: stats.memberCount, duplicateCount: stats.skippedCount }
|
||||
}
|
||||
|
||||
@@ -161,6 +174,11 @@ function incrementalImport(
|
||||
if (written > 0) {
|
||||
insertFtsEntries(db, onProgress)
|
||||
db.prepare('UPDATE meta SET imported_at = ?').run(Math.floor(Date.now() / 1000))
|
||||
try {
|
||||
generateIncrementalSessionIndex(db)
|
||||
} catch {
|
||||
/* non-fatal */
|
||||
}
|
||||
}
|
||||
|
||||
return { messageCount: written, memberCount: newMembers, duplicateCount: duplicates }
|
||||
|
||||
@@ -14,7 +14,6 @@ import {
|
||||
analyzeIncrementalImport as sharedAnalyzeIncremental,
|
||||
incrementalImport as sharedIncrementalImport,
|
||||
} from '@openchatlab/node-runtime'
|
||||
import { generateSessionIndex, generateIncrementalSessionIndex } from '@openchatlab/core'
|
||||
import type {
|
||||
StreamImportResult,
|
||||
StreamImportDeps,
|
||||
@@ -71,13 +70,6 @@ function buildStreamImportDeps(dbManager: DatabaseManager, onProgress?: ImportPr
|
||||
dbManager.deleteSessionDatabaseFiles(sessionId)
|
||||
},
|
||||
onProgress: onProgress ?? (() => {}),
|
||||
postImportHook(db) {
|
||||
try {
|
||||
generateSessionIndex(db)
|
||||
} catch {
|
||||
/* non-fatal: frontend can regenerate via generate-index route */
|
||||
}
|
||||
},
|
||||
generateSessionId,
|
||||
}
|
||||
}
|
||||
@@ -174,13 +166,6 @@ function buildIncrementalDeps(
|
||||
}
|
||||
},
|
||||
onProgress: onProgress ?? (() => {}),
|
||||
postImportHook(db) {
|
||||
try {
|
||||
generateIncrementalSessionIndex(db)
|
||||
} catch {
|
||||
/* non-fatal */
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user