perf(edit): load the draft documents as one concurrent wave

EditModeShell issued the 12 draft documents with a for-loop of awaits, then the
2 category-label files. It now starts two concurrent requests whose success and
failure handlers are attached in the same tick, so a label rejection landing
while the documents are still in flight is not an unhandled rejection. The two
failure branches are unchanged: a document failure is the offline state, a label
failure only disables the category rule. Measured through the dev proxy, the
same transport the app uses: 12 documents sequential 902 ms -> 210 ms for the
whole 14-request wave, 38768 bytes and 12 distinct payloads byte-identical to
the sequential loop.

nginx.conf now proxies /api/content/ to Gitea over HTTP/2 (proxy_http_version 2
+ a cleared Connection header), so the wave rides one pooled upstream connection
instead of one HTTP/1.1 connection per in-flight request. The stack's nginx
1.31.x already does HTTP/1.1 with upstream keepalive caching by default since
1.29.7, so no upstream block is declared and the envsubst contract is
untouched; the pipeline's test-before-touch nginx -t is what proves the image
accepts proxy_http_version 2.

Specs: spec-v4-live-edit.md row 25 + the draft-initialization bullet,
spec-v4-deploy-infra.md D14 + row 10, AGENTS.md nginx.conf line.
This commit is contained in:
dong.nguyen committed 2026-10-24 14:45:26 +07:00
1 parent 3126971852
commit 83da513931
5 files changed
+43 -12

No files matched your search

+28 -10
View File
@@ -155,10 +155,31 @@ export default function EditModeShell({ children }: { children: ReactNode }) {
// (§5.1); the bundle is only the offline fallback, flagged stale.
let offline = false;
let bases: Record<DraftDocId, DocBase> | null = null;
try {
// One concurrent wave instead of 14 serialized round-trips. The handlers
// are attached in the same tick the requests are made, so a label
// rejection that lands while the documents are still in flight is not an
// unhandled rejection; the two failure paths stay separate — a document
// failure is the offline state, a label failure only disables rule 7.
const docsRequest = Promise.all(
DRAFT_DOCS.map((meta) => fetchDoc(meta.file, branch)),
).then(
(docs) => ({ ok: true as const, docs }),
() => ({ ok: false as const }),
);
const labelsRequest = Promise.all([
fetchDoc(LABEL_FILES.vi, branch),
fetchDoc(LABEL_FILES.en, branch),
]).then(
([vi, en]) => ({ ok: true as const, vi, en }),
() => ({ ok: false as const }),
);
const docs = await docsRequest;
if (docs.ok) {
bases = {} as Record<DraftDocId, DocBase>;
for (const meta of DRAFT_DOCS) bases[meta.id] = await fetchDoc(meta.file, branch);
} catch {
DRAFT_DOCS.forEach((meta, index) => {
bases![meta.id] = docs.docs[index];
});
} else {
offline = true;
}
if (!bases) bases = bundledBase();
@@ -167,13 +188,10 @@ export default function EditModeShell({ children }: { children: ReactNode }) {
// says the label check could not run, and the rule is skipped rather
// than guessed at from a bundle that may predate the branch.
let labels: CategoryLabels | null = null;
try {
const [viLabels, enLabels] = await Promise.all([
fetchDoc(LABEL_FILES.vi, branch),
fetchDoc(LABEL_FILES.en, branch),
]);
labels = { vi: categoryMap(viLabels.data), en: categoryMap(enLabels.data) };
} catch {
const labelDocs = await labelsRequest;
if (labelDocs.ok) {
labels = { vi: categoryMap(labelDocs.vi.data), en: categoryMap(labelDocs.en.data) };
} else {
setLabelsUnavailable(true);
}