Skip to content

Commit 00fef25

Browse files
committed
perf(metadata-protocol): the served item read caches its caller-independent compiled answer (ADR-0156)
`getMetaItem`'s served face (the per-item read of every app bundle member) answers a by-name read of an app, object, view, page or dashboard from a per-engine cache while every source it reads is unchanged. The per-caller gate, mask, translation and ETag, and the live trailers, run every request. - objectql: `SchemaRegistry#revision`, moved by every public write; the public methods are classified read/write once, exhaustive by type, and the writes are wrapped (registry-revision.ts). - metadata: `MetadataManager#revision` and `loaderChangeMark()`; `FilesystemLoader#changeMark()` stats the type directories and files its reads touched. - metadata-protocol: meta-compile-cache.ts, stamped with the overlay generation and the three counters; confirms at its bound (`OS_METADATA_COMPILE_CACHE_TTL_MS`, 0 = uncached) with a store reading and the loader marks, and never renews an entry it cannot confirm. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5oyZgRX9Qc1ZHsMRQp
1 parent 24b6ae5 commit 00fef25

14 files changed

Lines changed: 1598 additions & 14 deletions
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
'@objectstack/metadata-protocol': patch
3+
'@objectstack/metadata': patch
4+
'@objectstack/objectql': patch
5+
---
6+
7+
perf(metadata-protocol): the served item read caches its caller-independent compiled answer (ADR-0156)
8+
9+
Clause-②: no
10+
Metadata-protocol: none
11+
12+
`getMetaItem` (the served face of `GET /api/v1/meta/:type/:name`, and the per-item read an app bundle makes for every app, object, view, page and dashboard it names) no longer recompiles an item whose sources have not changed. Every caller gets the same answer it got before, the response body and ETag included: only the server's work per request moves.
13+
14+
- **What is cached.** The compiled envelope of a by-name read of `app`, `object`, `view`, `page` and `dashboard` items, per engine. A read for a package, a state, a member or a draft preview is never cached. The per-caller gate, field mask, translation and ETag stay computed on every request, and the live trailers (`registration`, `disabledActions`, `cascadeDeleteObjects`) are read on every hit.
15+
- **What retires it.** Each source counts its own changes at its own mutation point: the `sys_metadata` overlay generation, the schema registry's `objectRevision` and a new `revision` that every public write of `SchemaRegistry` moves (the classification of its public methods is exhaustive by type), and a new `revision` on `MetadataManager`. Any move drops every entry. A source without its counter makes the cache decline.
16+
- **What another process can change.** After a bound (`OS_METADATA_COMPILE_CACHE_TTL_MS`, default 30000 ms) the cache confirms before it recompiles: a reading of the stored rows (count and latest change) and of each loader's backing store (`FilesystemLoader` stats the type directories and files its reads touched). If nothing moved, the entries stand for another bound. A loader that keeps no change mark makes every entry recompile at its bound, never renewed.
17+
- `OS_METADATA_COMPILE_CACHE_TTL_MS=0` is the uncached read, the same reads in the same order.
18+
19+
On a showcase Setup bundle, an immediate repeat made 213 database reads before and 9 after.

‎content/docs/deployment/environment-variables.mdx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@ With several replicas declared over the Redis cluster driver (`OS_CLUSTER_REPLIC
430430
| `OS_SANDBOX_WALL_CEILING_MS` | number | `30000` | Wall-clock ceiling (ADR-0102) — the backstop that cuts a hook/action body stuck on a host call that never settles (which burns no CPU, so the CPU budget alone would never fire). The effective ceiling is `max(this, cpuBudget)`, so it can never cut a body still inside its CPU budget. Positive integer only; unset keeps 30s. |
431431
| `OS_LOCALIZATION_CACHE_TTL_MS` | number | `30000` | Staleness bound, in milliseconds, for the cross-request cache of a workspace's reference localization (`timezone` / `locale` / `currency`, read from `sys_setting`) — leg C of #11633. `0` means **off**, a real path that restores the uncached query pattern exactly. Unlike `OS_AUTHZ_GRANTS_CACHE_TTL_MS` (which is off by default) this one ships **on**, because its invalidation is synchronous and in-process rather than TTL-bound: a `localization` settings change, a write to `sys_setting` or `sys_platform_setting` (the tables the answer is read from), and a non-`write` bump of the engine write epoch each retire a cached answer immediately. A write to any other object does not. So the TTL only bounds what none of these seams can see — a write made on another replica with no cluster bridge attached at all: neither the `metadata.mutated` channel's receipt path (`applyRemoteMetadataMutation` calls `bumpWriteEpoch`, #13609) nor the `authz.invalidated` bridge, both of which bump this same epoch when attached. ⚠️ A malformed value reads as `0` (off), the opposite arm from the grants variable and deliberately so: there `0` is also the default, whereas here folding `3OOO` (letter O) into the default would hand you a **longer** window than the one you were setting. Deployment config only — never a settings row, because `sys_setting` is the table this cache caches. |
432432
| `OS_METADATA_OVERLAY_CACHE_TTL_MS` | number | `30000` | Staleness bound, in milliseconds, for the cross-request cache of the `sys_metadata` overlay rows read inside `getMetaItems` (the list read) and `getMetaItem` (the served by-name read the REST API-exposure gate makes on every `/data` request) — leg D of #11633. `0` means **off**, a real path that restores the uncached query pattern exactly. Ships **on**, for the same reason as `OS_LOCALIZATION_CACHE_TTL_MS`: invalidation is synchronous and in-process, because every `sys_metadata` write goes through the engine, whose middleware retires the entry when the write's statement completes, before the next read. Outside a transaction that is the commit. Inside an engine transaction it is earlier than the commit: a read that lands between the statement and the commit can keep the pre-commit rows until the next `sys_metadata` write or the TTL. A write to any other object does not retire it; a non-`write` bump of the engine write epoch retires it wholesale. What is cached is the overlay ROW SET only — never the merged answer — so the SchemaRegistry, the MetadataService and the artifact table are re-consulted on every call, cached or not, and the read-side registry hydration keeps running on a cache hit. The TTL therefore bounds one thing: a write made on **another replica** with no cluster bridge attached at all — neither the `metadata.mutated` channel's own receipt path (`applyRemoteMetadataMutation` calls `bumpWriteEpoch` right after registry convergence, #13609) nor the `authz.invalidated` bridge, either of which retires this entry the moment it is attached and fires. ⚠️ A malformed value reads as `0` (off) — same arm and same reason as `OS_LOCALIZATION_CACHE_TTL_MS`. Deployment config only, never a settings row. |
433+
| `OS_METADATA_COMPILE_CACHE_TTL_MS` | number | `30000` | Bound, in milliseconds, for the per-environment cache of compiled item answers ([ADR-0156](https://github.com/objectstack-ai/objectstack/blob/main/docs/adr/0156-compiled-metadata-answer-cache-every-source-counts-its-own-changes.md)): the served item read (`getMetaItem`) of an app, object, view, page or dashboard, which the app bundle (`GET /api/v1/meta/app/:appId/bundle`) and the item reads make. `0` means **off**, a real path: the read is the uncached one, the same reads in the same order. Only the caller-independent answer is cached; the per-caller gate, field mask, translation and `ETag` are computed on every request. A local change is seen at once: the cache keeps the change counter of every source it reads (the `sys_metadata` overlay generation, the schema registry's `revision` and `objectRevision`, the metadata service's `revision`) and drops every entry when one moves; a source without its counter makes it decline. When the bound passes it confirms before it recompiles, with one reading of what this process cannot see (the `sys_metadata` row count and newest `updated_at`, and each metadata loader's own change mark: the file loader stats the directories and files its reads touched); unchanged, the entries stand for another bound; unreadable, nothing is renewed. The bound is therefore how long another replica's write with no cluster bridge, or a file edited under a running process, can stay unseen. ⚠️ A malformed value reads as `0` (off). Deployment config only, never a settings row. |
433434
| `OS_INLINE_SEED_BUDGET_MS` | number | `8000` | Time budget for synchronous seed execution at boot before deferring to a worker. |
434435
| `OS_TENANT_AUDIT` | flag | `1` | Set to `0` to silence the tenant-isolation audit warnings emitted by the SQL driver. |
435436

0 commit comments

Comments
 (0)