{"draft":null,"from":293,"to":294,"files":[{"path":"client/src/local-store.ts","added":38,"removed":7,"diff":"--- a/client/src/local-store.ts\n+++ b/client/src/local-store.ts\n@@ -189,6 +189,8 @@\n \tDatabaseSync: new (path: string) => Db;\n \thandle: (request: Request, env: unknown, ctx: unknown, issues: unknown) => Promise<Response>;\n \tProjectObject: new (ctx: unknown, env: unknown) => object;\n+\tIssueProject: new (ctx: unknown, env: unknown) => object;\n+\tissuesFetch: (request: Request, env: unknown, ctx: unknown, route: unknown) => Promise<Response>;\n };\n let server: Promise<Server> | undefined;\n \n@@ -240,7 +242,13 @@\n \t\t\t\t`local projects couldn't load the server's code: ${e instanceof Error ? e.message : String(e)}`,\n \t\t\t);\n \t\t}\n-\t\treturn { DatabaseSync: sqlite.DatabaseSync, handle: loaded.handle, ProjectObject: loaded.ProjectObject };\n+\t\treturn {\n+\t\t\tDatabaseSync: sqlite.DatabaseSync,\n+\t\t\thandle: loaded.handle,\n+\t\t\tProjectObject: loaded.ProjectObject,\n+\t\t\tIssueProject: loaded.IssueProject,\n+\t\t\tissuesFetch: loaded.issuesFetch,\n+\t\t};\n \t})();\n \treturn server;\n }\n@@ -256,6 +264,10 @@\n \tobject: object | undefined;\n \t/** PRAGMA data_version when this process last used the project: it changes when another process writes. */\n \tseen: number | undefined;\n+\t/** The project's issues, asks and news: issues.sqlite beside it, opened when a call first reaches them. */\n+\tissues?: { db: Db; storage: ReturnType<typeof storageOver> };\n+\t/** The issues object for the call under way: made again for each call, as another process may have written. */\n+\tissueObject?: object;\n }\n \n /** Every store file this process has open: closed when its command ends (closeLocalStores). */\n@@ -271,7 +283,8 @@\n \topened.clear();\n }\n \n-const PROJECT_PATH = /^\\/p\\/([^/]+)\\//;\n+/** A project's calls, and its issues, asks and news, which the open server keeps at /issues/p/<project>/. */\n+const PROJECT_PATH = /^(?:\\/issues)?\\/p\\/([^/]+)\\//;\n const NAME = /^[A-Za-z0-9._-]{1,100}$/;\n const json = (status: number, body: unknown) => Response.json(body, { status });\n \n@@ -312,8 +325,25 @@\n \t\t\t\treturn p.object;\n \t\t\t},\n \t\t},\n-\t\t// Issues, asks and news aren't in local projects yet: a start note's issue hooks find nothing to call.\n-\t\tISSUES_DO: { idFromName: (n: string) => n, get: () => ({}) },\n+\t\tISSUES_DO: {\n+\t\t\tidFromName: (n: string) => n,\n+\t\t\tget: (n: string) => {\n+\t\t\t\tconst p = open.get(n);\n+\t\t\t\tif (!p || n !== name) throw new LocalError(`no local project ${n}`);\n+\t\t\t\tif (p.issues === undefined || !opened.has(p.issues.db)) {\n+\t\t\t\t\tconst db = new opening!.DatabaseSync(join(dir, name, \"issues.sqlite\"));\n+\t\t\t\t\topened.add(db);\n+\t\t\t\t\tdb.exec(\"PRAGMA journal_mode = WAL; PRAGMA busy_timeout = 120000; PRAGMA synchronous = NORMAL\");\n+\t\t\t\t\tp.issues = { db, storage: storageOver(db) };\n+\t\t\t\t}\n+\t\t\t\t// Its writes need no lock of their own: every call holds the project file's (see below).\n+\t\t\t\tp.issueObject ??= new opening!.IssueProject(\n+\t\t\t\t\t{ id: { toString: () => n, name: n }, storage: p.issues.storage },\n+\t\t\t\t\tenv(name),\n+\t\t\t\t);\n+\t\t\t\treturn p.issueObject;\n+\t\t\t},\n+\t\t},\n \t});\n \treturn async (input, init = {}) => {\n \t\tconst s = await loadServer();\n@@ -329,7 +359,10 @@\n \t\theaders.set(\"authorization\", `Bearer ${LOCAL_TOKEN}`);\n \t\tconst request = new Request(url, { ...init, headers });\n \t\tconst waits: Promise<unknown>[] = [];\n+\t\t// Every call, issues ones too, holds the project file's lock, so local writers of the project and of its\n+\t\t// issues take one lock in one order.\n \t\tp.db.exec(\"BEGIN IMMEDIATE\");\n+\t\tp.issueObject = undefined;\n \t\ttry {\n \t\t\tconst version = (p.db.prepare(\"PRAGMA data_version\").get() as { data_version: number }).data_version;\n \t\t\tif (p.seen !== undefined && version !== p.seen) p.object = undefined;\n@@ -337,7 +370,7 @@\n \t\t\t\trequest,\n \t\t\t\tenv(name),\n \t\t\t\t{ waitUntil: (w: Promise<unknown>) => waits.push(w) },\n-\t\t\t\tissuesNone,\n+\t\t\t\ts.issuesFetch,\n \t\t\t);\n \t\t\tawait Promise.allSettled(waits);\n \t\t\t// The answer is read whole before the write is kept, so a body that fails to arrive keeps nothing either.\n@@ -358,5 +391,3 @@\n \t\t}\n \t};\n }\n-\n-const issuesNone = async () => json(404, { error: \"issues, asks and news aren't in local projects yet\" });"}],"unmatched":[]}