{"draft":null,"from":166,"to":167,"files":[{"path":"server/src/engine-project.ts","added":21,"removed":4,"diff":"--- a/server/src/engine-project.ts\n+++ b/server/src/engine-project.ts\n@@ -3,6 +3,7 @@\n // 2 MB) is split across rows and joined on load. Ported from the platform's worker/src/engine-project.ts; the\n // writer-adoption and R2 version parts are left out.\n \n+import { jsonValueChunks } from \"../../src/engine/json-value-chunks.ts\";\n import { blame, folderBlame, why } from \"../../worker/project/blame.ts\";\n import { feedEvents } from \"../../worker/project/feed.ts\";\n import { type Entry, type ProjectStore as LogStore, MemoryStore, Project } from \"../../worker/project/project.ts\";\n@@ -33,6 +34,22 @@\n \treturn parts;\n }\n \n+/** Retains one log row plus an encoder fragment, preserving legacy row boundaries. */\n+export function* streamedLogParts(value: unknown): IterableIterator<string> {\n+\tlet pending = \"\";\n+\tfor (const chunk of jsonValueChunks(value)) {\n+\t\tpending += chunk;\n+\t\twhile (pending.length > LOG_PART_CHARACTERS) {\n+\t\t\tlet end = LOG_PART_CHARACTERS;\n+\t\t\tconst last = pending.charCodeAt(end - 1);\n+\t\t\tif (last >= 0xd800 && last <= 0xdbff) end--;\n+\t\t\tyield pending.slice(0, end);\n+\t\t\tpending = pending.slice(end);\n+\t\t}\n+\t}\n+\tif (pending) yield pending;\n+}\n+\n /** The lines an entry's atoms write: what a loaded project's size grows with (#46, #56). */\n function linesIn(entry: Entry): number {\n \tlet n = 0;\n@@ -424,11 +441,11 @@\n \t\t\tif (keys > 0) this.storage.sql.exec(\"UPDATE counts SET value = value + ? WHERE name = 'keys'\", keys);\n \t\t\tlet chars = 0;\n \t\t\tfor (const entry of entries) {\n-\t\t\t\tconst json = JSON.stringify(entry);\n-\t\t\t\tlogParts(json).forEach((text, part) => {\n+\t\t\t\tlet part = 0;\n+\t\t\t\tfor (const text of streamedLogParts(entry)) {\n \t\t\t\t\tchars += text.length;\n-\t\t\t\t\tthis.storage.sql.exec(\"INSERT INTO log (seq, part, text) VALUES (?, ?, ?)\", next, part, text);\n-\t\t\t\t});\n+\t\t\t\t\tthis.storage.sql.exec(\"INSERT INTO log (seq, part, text) VALUES (?, ?, ?)\", next, part++, text);\n+\t\t\t\t}\n \t\t\t\tnext++;\n \t\t\t}\n \t\t\t// Chars are only added to once counted: a log from before the count is summed whole first (logSize)."}],"unmatched":[]}