MCPcopy Create free account
hub / github.com/IgorWarzocha/howcode / syncSessionSummaries

Function syncSessionSummaries

desktop/thread-state-db/session-writes.ts:42–82  ·  view source on GitHub ↗
(cwd: string, sessions: SessionSummaryRecord[])

Source from the content-addressed store, hash-verified

40}
41
42export 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
84export function upsertThreadSummary(session: SessionSummaryRecord) {
85 const db = getThreadStateDatabase()

Callers 1

syncShellIndexFunction · 0.90

Calls 7

getThreadStateDatabaseFunction · 0.90
ensureProjectFunction · 0.90
runInTransactionFunction · 0.90
getDuplicateSessionIdsFunction · 0.85
getSessionThreadIdFunction · 0.85
prepareMethod · 0.80
runMethod · 0.80

Tested by

no test coverage detected