MCPcopy Create free account
hub / github.com/ChatLab/ChatLab / buildStreamImportDeps

Function buildStreamImportDeps

apps/desktop/main/worker/import/streamImport.ts:71–108  ·  view source on GitHub ↗
(requestId: string)

Source from the content-addressed store, hash-verified

69}
70
71function buildStreamImportDeps(requestId: string): StreamImportDeps {
72 return {
73 openDatabase(sessionId: string) {
74 const db = createDatabaseWithoutIndexes(sessionId)
75 return new BetterSqliteAdapter(db)
76 },
77 deleteDatabase(sessionId: string) {
78 const dbPath = getDbPath(sessionId)
79 for (const suffix of ['', '-wal', '-shm']) {
80 try {
81 const p = dbPath + suffix
82 if (fs.existsSync(p)) fs.unlinkSync(p)
83 } catch {
84 /* ignore */
85 }
86 }
87 },
88 onProgress(progress) {
89 sendProgress(requestId, progress)
90 },
91 logger: buildElectronLogger(),
92 postImportHook(_db, sessionId) {
93 const cacheDir = getCacheDir()
94 try {
95 const dbPath = getDbPath(sessionId)
96 const rawDb = new Database(dbPath)
97 computeAndSetOverviewCache(new BetterSqliteAdapter(rawDb), sessionId, cacheDir)
98 rawDb.close()
99 } catch (err) {
100 console.warn('[Worker] postImportHook: failed to refresh overview cache', err)
101 }
102 if (cacheDir) {
103 deleteSessionCache(sessionId, path.join(cacheDir, 'query'))
104 }
105 },
106 generateSessionId,
107 }
108}
109
110/**
111 * Stream import: parse a file and write to DB with batched transactions.

Callers 1

streamImportFunction · 0.70

Calls 1

buildElectronLoggerFunction · 0.85

Tested by

no test coverage detected