Public: anyone can read this; the crew can change it.

resolveAppHostname asks the database once per hostname, not once per call #17833

opened this

Merged 4h 44m ago, live in production

resolveAppHostname now keeps its answer for each host, so asking about the same host again no longer re-reads the app, repository and owner rows (#17824). The callers. No loop calls it once per row.

Notes

opened this

resolveAppHostname now keeps its answer for each host, so asking about the same host again no longer re-reads the app, repository and owner rows (#17824).

The callers. No loop calls it once per row. It is called from:

  • src/http/server.ts:1059 and src/spawn/host.ts:1104, through resolveAppHost
  • src/apps/here.ts, src/apps/preview_view.ts, src/web/pages/apps.ts (/apps/open) and src/http/routes/operations.ts (/__forge/domains/ask), each once per call

The 2,104 queries a minute come from src/http/server.ts:1059. It runs on every request to every app host, assets included. Requests to the forge's own host go through the same call and look up a verified custom domain.

The fix. It reuses the existing Stamped memo (src/kernel/stamped.ts) and the write clock (src/core/write_clock.ts), as src/web/map_snapshot.ts and src/actions/explore.ts already do. Each database gets one memo, keyed by the apps domain and the host. An entry is used only while the write clock hasn't moved. Any write that could change the answer moves the clock: a suspension, a slug change or a domain verified or removed. So the next lookup sees it, and #831 still holds. Entries also expire after 5 s, and the memo holds at most 1,024 hosts. Inside a transaction there is no stamp, so nothing is cached. Each lookup still runs one cheap write-clock read (total_changes() plus data_version), which reads no table.

Not done.

  • Callers aren't handed a resolved value; the memo makes that unnecessary.
  • The clock is forge-wide, so any write that isn't telemetry empties the memo. That costs some cache hits but never gives a stale answer.

Test. test/app-host-memo.test.ts:

  • 51 lookups of one host run the app, repo, domain and user queries only once. This fails when the memo is switched off.
  • A suspended owner's app is "unknown" at once and comes back at once after the suspension is lifted.
  • A renamed slug is seen at once.

Checks run. bun x tsc --noEmit and bun scripts/gate.ts (0 rules failed) pass. These suites pass: app-host-memo, suspended-hidden, app-variants, apps-adversarial, apps-proxy-overhead, app-domains, domains, core-domains, apps-pill-where and archived-hidden-everywhere. One test was skipped, a socket-bound case this sandbox can't run. scripts/fast.ts named 2,990 test files because proxy.ts is imported nearly everywhere, so those weren't run here. The forge's check runs the whole suite.

How to try it. bun test test/app-host-memo.test.ts.

🤖 Generated with Claude Code

Closes #17824

commented

resolveAppHostname now keeps its answer for each host, so asking about the same host again no longer re-reads the app, repository and owner rows (#17824).

The callers. No loop calls it once per row. It is called from:

  • src/http/server.ts:1059 and src/spawn/host.ts:1104, through resolveAppHost
  • src/apps/here.ts, src/apps/preview_view.ts, src/web/pages/apps.ts (/apps/open) and src/http/routes/operations.ts (/__forge/domains/ask), each once per call

The 2,104 queries a minute come from src/http/server.ts:1059. It runs on every request to every app host, assets included. Requests to the forge's own host go through the same call and look up a verified custom domain.

The fix. It reuses the existing Stamped memo (src/kernel/stamped.ts) and the write clock (src/core/write_clock.ts), as src/web/map_snapshot.ts and src/actions/explore.ts already do. Each database gets one memo, keyed by the apps domain and the host. An entry is used only while the write clock hasn't moved. Any write that could change the answer moves the clock: a suspension, a slug change or a domain verified or removed. So the next lookup sees it, and #831 still holds. Entries also expire after 5 s, and the memo holds at most 1,024 hosts. Inside a transaction there is no stamp, so nothing is cached. Each lookup still runs one cheap write-clock read (total_changes() plus data_version), which reads no table.

Not done.

  • Callers aren't handed a resolved value; the memo makes that unnecessary.
  • The clock is forge-wide, so any write that isn't telemetry empties the memo. That costs some cache hits but never gives a stale answer.

Test. test/app-host-memo.test.ts:

  • 51 lookups of one host run the app, repo, domain and user queries only once. This fails when the memo is switched off.
  • A suspended owner's app is "unknown" at once and comes back at once after the suspension is lifted.
  • A renamed slug is seen at once.

Checks run. bun x tsc --noEmit and bun scripts/gate.ts (0 rules failed) pass. These suites pass: app-host-memo, suspended-hidden, app-variants, apps-adversarial, apps-proxy-overhead, app-domains, domains, core-domains, apps-pill-where and archived-hidden-everywhere. One test was skipped, a socket-bound case this sandbox can't run. scripts/fast.ts named 2,990 test files because proxy.ts is imported nearly everywhere, so those weren't run here. The forge's check runs the whole suite.

How to try it. bun test test/app-host-memo.test.ts.

🤖 Generated with Claude Code

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs