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

The cold front page build is slow: batch the per-repo canRead queries and the runtime status scan #6139

Parked opened this
Closed without merging

A cold build of / now asks the owner-standing question once for all repos and reads each app's production status directly. The new test and test/front.test.ts pass. I didn't run the full bun test, and I didn't time a cold build, so the under-10 ms target isn't measured.

Notes

stopped parked by the crew deploy c70fa2a

opened this

A cold build of / now asks the owner-standing question once for all repos and reads each app's production status directly. The new test and test/front.test.ts pass. I didn't run the full bun test, and I didn't time a cold build, so the under-10 ms target isn't measured. bun x tsc --noEmit couldn't run here: the bun types are missing from the sandbox.

  • canRead batching: strangerReadable(db, repos) in src/core/repos.ts is new. It checks owner standing for every repo in one query per 400 ids. A public repo with an owner in good standing is readable without another query. Only non-public repos get the full canRead(db, repo, undefined), so the two always agree. frontPage in src/actions/front.ts uses it for the pinned and public repos together.
  • Status scan: frontPage now calls runtime.envStatus(record, "production"), which is a map lookup. Before, it scanned every environment of every app with runtime.status. No change was needed in src/apps/runtime.ts.
  • Test: test/stranger-readable.test.ts checks strangerReadable against canRead for a public repo, a private repo and a suspended owner's repo.

I left the per-owner isActive check as it was, since owners already load in one query.

To try it, run bun test test/stranger-readable.test.ts test/front.test.ts.

Closes #6136

7 earlier comments
commented

A cold build of / now asks the owner-standing question once for all repos and reads each app's production status directly. The new test and test/front.test.ts pass. I didn't run the full bun test, and I didn't time a cold build, so the under-10 ms target isn't measured. bun x tsc --noEmit couldn't run here: the bun types are missing from the sandbox.

  • canRead batching: strangerReadable(db, repos) in src/core/repos.ts is new. It checks owner standing for every repo in one query per 400 ids. A public repo with an owner in good standing is readable without another query. Only non-public repos get the full canRead(db, repo, undefined), so the two always agree. frontPage in src/actions/front.ts uses it for the pinned and public repos together.
  • Status scan: frontPage now calls runtime.envStatus(record, "production"), which is a map lookup. Before, it scanned every environment of every app with runtime.status. No change was needed in src/apps/runtime.ts.
  • Test: test/stranger-readable.test.ts checks strangerReadable against canRead for a public repo, a private repo and a suspended owner's repo.

I left the per-owner isActive check as it was, since owners already load in one query.

To try it, run bun test test/stranger-readable.test.ts test/front.test.ts.

commented

The cold front-page build now asks once, for all repos, whether the viewer owns them. It no longer runs a canRead query per repo. It also reads production status directly instead of scanning runtime status. This was already committed and pushed on the branch (ced8a733), so this run added no new commits.

  • Code: the change is in src/actions/front.ts and a new helper in src/core/repos.ts.
  • Test: test/stranger-readable.test.ts is new for the batched standing read.
  • Checks: that test file passes and tsc --noEmit is clean. I did not get a finished full bun test run. The forge runs the whole check on the push.
  • Not done: I took no timings, so the speed-up is not measured. I did not touch the signed-out shelf or the issues-list batching, which landed separately in #6133 and #6135.
  • To try it: load / cold on the preview and compare it with production.
commented

I made no changes this run. The feedback request had no new comment, review or instruction on #6139. The branch is clean and ced8a733 is already pushed.

I re-ran bun test test/stranger-readable.test.ts test/front.test.ts and all 15 tests pass. I did not run the full bun test, the type check, or a timing of a cold build.

What the pull does:

  • Owner standing: strangerReadable(db, repos) in src/core/repos.ts is a new helper. It asks once for all repos whether the owner is in good standing, in batches of 400 ids, instead of running canRead per repo. Only non-public repos fall back to the full canRead(db, repo, undefined), so the two always agree.
  • Front page: frontPage in src/actions/front.ts uses it for the pinned and public repos together.
  • Production status: frontPage now calls runtime.envStatus(record, "production"), a map lookup. Before, it scanned every environment of every app with runtime.status.
  • Test: test/stranger-readable.test.ts is new. It compares strangerReadable with canRead for a public repo, a private repo and a suspended owner's repo.

Left out: I took no timings, so the speed-up is not measured. I left the per-owner isActive check as it was, since owners already load in one query.

To try it: run bun test test/stranger-readable.test.ts test/front.test.ts, or load / cold on the preview and compare it with production.

🤖 Generated with Claude Code

commented

A cold build of / now asks "which repos can this owner read?" once for all of an owner's repos, instead of once per repo. I haven't done the same for the runtime status scan. The change is on the branch and already pushed, and nothing new was needed this run. I checked it by running the four front-page test files, which pass. The full bun test run hit the 120 s limit, so I haven't seen it finish. I never ran the type check or scripts/design-lint.ts.

  • Batched reads: src/core/repos.ts gets a helper that works out an owner's standing once and applies it to every repo. src/actions/front.ts uses it, so the per-repo queries (twice over owners) are gone.
  • Production status: src/actions/front.ts reads the production status directly (per the commit message) rather than calling runtime.status, which scans every env of every app. I did not change src/apps/runtime.ts itself.
  • Tests: test/stranger-readable.test.ts has 61 new lines covering the batched read.
  • Not done: I never measured the cold-build time against the issue's 10 ms target.

To try it: run bun test test/stranger-readable.test.ts, then load / right after a database write and time the response.

commented

Parked by the crew: the check failed ("verify an email from the People screen > an admin verifies the person under the cursor and the row changes") and the decider saw no point in another try try 1: src/actions/front.ts, src/core/repos.ts, test/stranger-readable.test.ts

commented

The three failing studio tests are fixed and pushed as 0c10612a. The front page now reads production status through envStatus, and the test helper only faked status. So no app looked live and the "Apps, live." shelf rendered empty.

The fix is in test/helpers/studio.ts: serving now fakes envStatus as well as status. This is a test-only change. The test was wrong, not the front-page code.

test/studio-changes.test.ts and test/stranger-readable.test.ts pass (27 tests), and test/front.test.ts passes (14). tsc is clean. I did not run the full suite; the forge runs it on this push.

test/front.test.ts also fakes status, but it passes unchanged, so I left it alone.

commented

The three test/front-speed.test.ts failures are fixed and pushed as c70fa2a1. After the push I did not wait for the forge's check, so whether it passes is still open.

Cause: test/front-speed.test.ts landed on main after I branched. The front page now reads production status through envStatus, and that test faked only status. With nothing reading as live, the shelf came back empty and the three tests failed.

Fix: I merged origin/main into the branch, then made the test fake envStatus as well as status. This is a test-only change; the test was wrong, not the front-page code.

Locally, front-speed, front and studio-changes all pass (46 tests) and tsc is clean. I did not run the full suite.

commented

Parked by the crew: the check stayed red through 2 automatic tries

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs