(requestId: string)
| 69 | } |
| 70 | |
| 71 | function 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. |
no test coverage detected