MCPcopy Create free account
hub / github.com/Dhravya/notty / finalizeEditSession

Method finalizeEditSession

src/durable-objects/user-notes.ts:341–366  ·  view source on GitHub ↗
(noteId: string, sessionId: string, reason = "finalize")

Source from the content-addressed store, hash-verified

339 let prevContent: string;
340 try {
341 prevContent = await this.reconstructVersion(head.id, noteId, { strict: true });
342 } catch {
343 return null;
344 }
345 if (!isEmptyDoc(prevContent)) return null;
346 }
347
348 // Coalesce autosave churn: a session version right after another
349 // session version just moves that version forward instead of stacking
350 // a new entry per tab-switch/idle. Never amend a version that another
351 // branch also points at (branch create copies head_version_id) — that
352 // would silently rewrite the other branch's snapshot in place.
353 const now = Math.floor(Date.now() / 1000);
354 const headSharedWithOtherBranch = head ? this.sql.exec(
355 "SELECT 1 FROM note_branches WHERE head_version_id = ? AND id != ? LIMIT 1", head.id, branch.id
356 ).toArray().length > 0 : false;
357 if (
358 kind === "session" && head?.kind === "session" && head.storage === "r2" &&
359 !headSharedWithOtherBranch &&
360 now - head.created_at < this.SESSION_AMEND_WINDOW_S
361 ) {
362 await this.bucket.put(head.data, content, { httpMetadata: { contentType: "application/json" } });
363 this.sql.exec(
364 "UPDATE note_versions SET title = ?, summary = ?, content_hash = ?, created_at = unixepoch() WHERE id = ?",
365 title, summary, hash, head.id
366 );
367 return head.id;
368 }
369

Callers 1

fetchMethod · 0.95

Calls 2

getNoteMethod · 0.95
createVersionMethod · 0.95

Tested by

no test coverage detected