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

Function upsertThreadSummary

desktop/thread-state-db/session-writes.ts:84–129  ·  view source on GitHub ↗
(session: SessionSummaryRecord)

Source from the content-addressed store, hash-verified

82}
83
84export function upsertThreadSummary(session: SessionSummaryRecord) {
85 const db = getThreadStateDatabase()
86 ensureProject(session.cwd)
87
88 const storedThreadForPath = db
89 .prepare(
90 `
91 SELECT id, session_path AS sessionPath
92 FROM threads
93 WHERE session_path = ?
94 `,
95 )
96 .get(session.sessionPath) as ThreadIdPathRow | undefined
97 const storedDuplicateIdRows = db
98 .prepare(
99 `
100 SELECT id, session_path AS sessionPath
101 FROM threads
102 WHERE (id = ? OR id LIKE ? ESCAPE '\\')
103 AND session_path != ?
104 `,
105 )
106 .all(session.id, `${escapeLikePattern(session.id)}:%`, session.sessionPath) as ThreadIdPathRow[]
107
108 const threadId =
109 storedThreadForPath?.id && storedThreadForPath.id !== session.id
110 ? storedThreadForPath.id
111 : storedDuplicateIdRows.length > 0
112 ? getDisambiguatedThreadId(session)
113 : session.id
114
115 db.prepare(
116 `
117 INSERT INTO threads (id, cwd, session_path, title, last_modified_ms)
118 VALUES (?, ?, ?, ?, ?)
119 ON CONFLICT(session_path) DO UPDATE SET
120 id = excluded.id,
121 cwd = excluded.cwd,
122 title = excluded.title,
123 last_modified_ms = excluded.last_modified_ms,
124 updated_at = CURRENT_TIMESTAMP
125 `,
126 ).run(threadId, session.cwd, session.sessionPath, session.title, session.lastModifiedMs)
127
128 return threadId
129}
130
131export function setSessionNativeExtensions(sessionPath: string, enabled: string[]) {
132 const db = getThreadStateDatabase()

Callers 4

persistHostThreadUpdateFunction · 0.90

Calls 8

getThreadStateDatabaseFunction · 0.90
ensureProjectFunction · 0.90
escapeLikePatternFunction · 0.85
getDisambiguatedThreadIdFunction · 0.85
getMethod · 0.80
prepareMethod · 0.80
allMethod · 0.80
runMethod · 0.80

Tested by

no test coverage detected