(cwd: string, sessions: SessionSummaryRecord[])
| 40 | } |
| 41 | |
| 42 | export function syncSessionSummaries(cwd: string, sessions: SessionSummaryRecord[]) { |
| 43 | const db = getThreadStateDatabase() |
| 44 | const insertProject = db.prepare( |
| 45 | ` |
| 46 | INSERT INTO projects (cwd, name, collapsed, hidden) |
| 47 | VALUES (?, ?, 1, 0) |
| 48 | ON CONFLICT(cwd) DO UPDATE SET |
| 49 | name = excluded.name, |
| 50 | updated_at = CURRENT_TIMESTAMP |
| 51 | `, |
| 52 | ) |
| 53 | const insertThread = db.prepare( |
| 54 | ` |
| 55 | INSERT INTO threads (id, cwd, session_path, title, last_modified_ms) |
| 56 | VALUES (?, ?, ?, ?, ?) |
| 57 | ON CONFLICT(session_path) DO UPDATE SET |
| 58 | id = excluded.id, |
| 59 | cwd = excluded.cwd, |
| 60 | title = excluded.title, |
| 61 | last_modified_ms = excluded.last_modified_ms, |
| 62 | updated_at = CURRENT_TIMESTAMP |
| 63 | `, |
| 64 | ) |
| 65 | ensureProject(cwd) |
| 66 | runInTransaction(db, () => { |
| 67 | const duplicateSessionIds = getDuplicateSessionIds(sessions) |
| 68 | |
| 69 | for (const session of sessions) { |
| 70 | insertProject.run(session.cwd, path.basename(session.cwd) || session.cwd) |
| 71 | const threadId = getSessionThreadId(session, duplicateSessionIds) |
| 72 | |
| 73 | insertThread.run( |
| 74 | threadId, |
| 75 | session.cwd, |
| 76 | session.sessionPath, |
| 77 | session.title, |
| 78 | session.lastModifiedMs, |
| 79 | ) |
| 80 | } |
| 81 | }) |
| 82 | } |
| 83 | |
| 84 | export function upsertThreadSummary(session: SessionSummaryRecord) { |
| 85 | const db = getThreadStateDatabase() |
no test coverage detected