You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit e2a0e90
Browse filesBrowse the repository at this point in the historyBrowse files
perf(metadata-protocol): one form request reads the view list and each type's stored rows once (#38164)
Fixes#37709
Clause-②: yes (widening) —
ObjectStackProtocolImplementation.readFormRequest
Metadata-protocol: none
## 维护者速读
- 用户无感:匿名公开表单页和按名读取表单时,返回的内容与以前完全一样,只是同一次请求里不再把同一批元数据反复读好几遍。
- 属于"表单独立成为元数据类型"这一系列的收尾,解决上一轮评审留下的"同一请求重复读库"这一条遗留项。
- 若出错,公开表单可能打不开或判断错一个表单是否公开;改动不碰任何存储数据,可直接撤回。
- 无。
## What changes
The effective `form` read (ADR-0159 D5) resolves over both types: the
generic `form` list, the projection of the `view` list, and the
cross-type resolution (step 3) over the stored rows of both types. Each
of those readings, and each of the five reads an anonymous form door
makes, asked the store for the same rows again.
- **`packages/metadata-protocol/src/protocol-form-reads.ts`.**
`formRequestScope(host)`: one request's reading, over which each stored
row set (per type and package binding) and each flattened list (per
request, audience and layer) is read once. `readEffectiveFormList` reads
through it, so the generic `form` list and step 3 share one reading of
the `form` rows, and the `view` list and step 3 share one reading of the
`view` rows. `readInFormRequest(read)` runs `read` as one request
reading (an AsyncLocalStorage store): every protocol list read inside it
over the same host shares one scope, and once `read` settles the scope
memoizes nothing, so nothing outlives the request. The stored rows of
step 3 stay read whole (a container row's name is not the name its
expansion writes); they are read once per request. The
`readEffectiveFormList` docblock now states that.
- **`packages/metadata-protocol/src/protocol-meta-list-reads.ts`.**
`readFlattenedMetaItems` takes an optional stored-row reader (the
scope's); `getMetaItems` and `getMetaItemsPerPackage` read through the
open request reading when there is one; the package-scoped `form` list
face reads its envelope through the same scope.
- **`packages/metadata-protocol/src/protocol.ts`.** The private
`readFlattenedMetaItems` passes the row reader on. New server-only
extension `readFormRequest(read)` (feature-detected by the doors, like
`getMetaItemsPerPackage` and `getUnreadableFormBodies`): runs `read` as
one request reading.
- **`packages/rest/src/form-routes.ts`** (outside the claim's file
surface; the measured producer of the repeated door reads, see
Acceptance notes). `resolveFormBySlug` makes its five reads inside
`readFormRequest` when the protocol serves it, and exactly as before
otherwise. Both doors (`GET /forms/:slug`, `POST /forms/:slug/submit`)
go through it.
- **`packages/metadata-protocol/src/protocol-meta-item-reads.ts`.**
Comment only at `readEffectiveFormItem`: on this tree it calls
`readEffectiveForms` once (not up to three times), and that one call now
reads each row set once.
Every answer is unchanged: the same items, in the same order, from the
same served-row order. The ADR-0159 D5 cross-type resolution is
untouched; `names` and `packageId` handling is untouched (`names` was
already pushed into both generic reads, and the reason `packageId` is
not pushed down was already stated in the `readEffectiveFormList`
docblock, both landed in #37422's rework; confirmed on this tree, not
redone).
### Measured counts (real protocol, real `ObjectQL` + SQLite store,
`OS_METADATA_OVERLAY_CACHE_TTL_MS=0`, one warm-up request)
"Row-set read" = one `readActiveOverlayRows` call (one `sys_metadata`
statement under the singular type, plus one under the plural when the
singular answers no row).
| Request | Form shape | `view` list (effective) before → after | `view`
row sets before → after | `form` row sets before → after |
|:---|:---|:---|:---|:---|
| by-name `form` read | authored `form` item | 1 → 1 | 2 → 1 | 2 → 1 |
| by-name `form` read | old-shape `formViews` entry | 1 → 1 | 1 → 1 | 1
→ 1 |
| form-door GET | authored `form` item | 2 → 1 | 5 → 1 | 3 → 1 |
| form-door GET | old-shape `formViews` entry | 2 → 1 | 4 → 1 | 2 → 1 |
Before = `origin/main` 93fa911 (with #37422 merged); after = this
branch. The by-name read also issues one row read predicated on the name
(the generic by-name read's own, `readItemActiveRows`), before and
after. The door reads the `form` list, the per-package `form` layer and
the per-package `view` layer once each, before and after. With the row
cache on (default 30 s) the repeated reads were cache hits at the SQL
level, but each still ran its parse and merge; with it off (or on a cold
or invalidated cache) each was a statement.
## Tests
- New `packages/rest/src/public-form-reads-once-37709.test.ts` (8 cases,
both form shapes): the by-name read and the door GET read the `view`
list once and each type's row sets once (exact counts, answers
asserted); CONTROL 1, two requests read twice (the scope never spans
requests); CONTROL 2, the five door calls outside one reading (a
protocol without `readFormRequest`) read the `view` list twice and the
`view` rows four times, so the counter sees a repeated read when there
is one.
-
`packages/rest/src/rest-write-route-hook-refusal-sentence.ledger.test.ts`:
its catch-all protocol double rejects every method it does not list, and
the door now feature-detects `readFormRequest`, so the double's reads
table gains one pass-through entry, as it gained
`getMetaItemsPerPackage` and `getUnreadableFormBodies` when those door
extensions landed. No assertion changed. Every other form-door and D5
test is unchanged and green.
<details><summary>Suites on f97bc7d (merged with
origin/main)</summary>
- `@objectstack/metadata-protocol` `vitest run`: Test Files 372 passed,
9 skipped (381); Tests 23605 passed, 45 skipped.
- `@objectstack/rest` `vitest run --project local`: Test Files 433
passed (433); Tests 8981 passed, 351 skipped.
- `pnpm --filter @objectstack/metadata-protocol typecheck`, `pnpm
--filter @objectstack/rest typecheck`: exit 0.
- Final head 73983ef changes only `protocol.ts` text after that run
(the `readFlattenedMetaItems` docblock reflowed and the new method's
docblock made one line, so the facade stays at its 11705-line ceiling,
`check:facade-delegation-only`). On it: rebuilt, both typechecks exit 0,
and the pin plus 11 form-door files: Test Files 12 passed (12), Tests
898 passed (898).
</details>
<details><summary>Ablations on 6178fb1 (scripts/ablation-replace.mjs,
each leg built and checked in dist with
scripts/ablation-dist-preflight.mjs)</summary>
- A1, the effective `form` read without its scope (drop `host =
formRequestScope(host)` in `readEffectiveFormList`): 2 failed / 6 passed
(the by-name read of an authored `form` item, and CONTROL 1).
- A2, `readFormRequest` opens no reading (`readInFormRequest(read)`
replaced by calling `read` directly): 4 failed / 4 passed (the door GET
in both shapes, and CONTROL 1 in both).
- A3, the scope's list reads read their rows outside it (no row reader
passed): 6 failed / 2 passed.
- Restore leg: every marker absent from dist, tree clean against HEAD,
pin 8/8 green.
</details>
<details><summary>Local gates on 73983ef (the 75 families
`dispatch-gates.mjs --commands` derives for this diff)</summary>
- All 75 commands exit 0, each exit captured before any pipe. `pnpm
check:dual-build-cjs-loads` first answered PREREQUISITE NOT MET (exit 3:
it reads every package's `dist/`), and exit 0 when re-run after
`check:type-check-debt`'s full build on the same head (126 require entry
points across 74 packages load).
- `check:facade-delegation-only` held the line: `protocol.ts` is at its
11705-line ceiling (it went red at 11719 on f97bc7d, fixed in
73983ef).
- `dispatch-gates.mjs --ran`: 75 derived, 75 run, 0 NOT-MEASURED, 0
UNRUN.
- Raw control-byte self-scan of the changed files: no match.
</details>
## Acceptance notes
- **Landing point outside the claim's file surface:
`packages/rest/src/form-routes.ts`.** Measurement shows the door's
repeated `view`-list and row reads come from its five separate protocol
calls; no change inside `packages/metadata-protocol` alone can share a
reading across them. A first cut answered the five reads through one new
protocol call; it bypassed the doubles four existing door tests install
by overriding `getMetaItems` / `getMetaItemsPerPackage` /
`getUnreadableFormBodies` on a real protocol, so the door keeps its five
calls and runs them inside one request reading instead.
- **Premise check.** On 93fa911 `readEffectiveFormItem` calls
`readEffectiveForms` once (the card's "up to three times" no longer
holds); the repeats were inside that one call (the `form` and `view` row
sets twice each).
- **New seam worth a reviewer's eye:** `readFormRequest` is a new public
method on `ObjectStackProtocolImplementation` (server-only,
feature-detected), and `metadata-protocol` now uses `AsyncLocalStorage`
(`node:async_hooks`; the package is already node-only).
## Verification
First read, by risk:
1. `packages/metadata-protocol/src/protocol-form-reads.ts`,
`formRequestScope` and `readInFormRequest`: a memoized list is one
object handed to several callers in the same request (every caller reads
it, none writes it), and the `live()` check that stops memoizing once
the request settles.
2. `packages/rest/src/form-routes.ts`, `resolveFormBySlug`: the five
reads inside `inOneReading`, in their old order.
3. `packages/metadata-protocol/src/protocol-meta-list-reads.ts`:
`readRows` at the active-row read of `readFlattenedMetaItems`, and
`inFormRequestScope` in `getMetaItems` / `getMetaItemsPerPackage`.
Two-minute check: `pnpm --filter @objectstack/metadata-protocol build &&
pnpm --filter @objectstack/rest exec vitest run
src/public-form-reads-once-37709.test.ts` prints `Tests 8 passed (8)`.
---
_Generated by [Claude
Code](https://claude.ai/code/session_017xRBcSAaBEfQpU2yJexSJ8)_
<!-- signed: repo:objectstack#8 · sunhaolin ·
session_017xRBcSAaBEfQpU2yJexSJ8 -->
---------
Co-authored-by: Claude <noreply@anthropic.com>
The effective `form` read resolves over both types (ADR-0159 D5): the generic `form` list, the projection of the `view` list, and the cross-type resolution over the stored rows of both types. Those readings asked for the same stored rows separately, and an anonymous form door made five protocol calls (the `view` list, the `form` list, the unreadable bodies and both per-package layers), each reading the rows again. With the overlay row cache off, a by-name `form` read read the `form` and `view` rows twice each, and a form-door GET read the `view` list twice, the `view` rows five times and the `form` rows three times.
12
+
13
+
-**`@objectstack/metadata-protocol`.** The effective `form` read now reads through one request scope: each stored row set (per type and package binding) and each flattened list is read once per request, and nothing is kept past the request. A new server-only extension, `readFormRequest(read)`, runs `read` as one request's reading: the `getMetaItems`, `getMetaItemsPerPackage` and `getUnreadableFormBodies` calls inside it share that one scope, each answering what it answers on its own.
14
+
-**`@objectstack/rest`.** The form doors (`GET /forms/:slug`, `POST /forms/:slug/submit`) make their five reads inside `readFormRequest` when the protocol serves it, and as before otherwise.
15
+
16
+
Every answer is unchanged: the same items, in the same order, from the same served-row order. Nothing to migrate.
0 commit comments