mike/backend/src
QA Runner 5f8e4ab4d8 fix: batch directory-modal project fetch instead of N+1 getProject burst
Every directory picker (AddDocumentsModal, UseWorkflowModal, the assistant
project selector) loads its "Projects" tab through useDirectoryData, which
fired one GET /projects/:id for EVERY existing project the moment the modal
opened. Each of those requests costs an auth verification against GoTrue
plus ~6 PostgREST queries, so an account with N projects produced an
~8xN-request burst on the Supabase gateway per modal open.

Under that burst the gateway genuinely falls over: measured locally against
the Supabase CLI stack, overlapping modal-open storms drove GoTrue into
Postgres connection exhaustion ("failed to connect ... context deadline
exceeded") and produced 467x 500 + 641x 504 on /auth/v1/user in a single
run — surfacing to users as failed project creates/loads, and to the e2e
suite as the intermittent Kong 502s its specs currently retry around.

Fix: GET /projects now accepts ?include=documents and returns each
project's documents from one batched query (same attach helpers as
GET /projects/:id, run once across all documents), and useDirectoryData
uses it. A modal open is now 1 API request and a fixed number of DB
queries regardless of project count. After the change the same storm
harness produced zero 5xx and zero auth failures.

[Cherry-pick overlap note: this same commit is submitted separately as the
olp-pr/directory-fetch-storm PR, where it belongs (production fix). It is
carried on this e2e branch only so the de-retried suite passes here; on
merge of both branches git resolves the duplicate cleanly.]

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-20 11:30:22 -07:00
..
lib feat: refresh workflows and workflow editor UI 2026-07-20 03:04:47 +08:00
middleware Sync workflow, asst extra input, excel + ppt support and modal updates 2026-07-04 23:24:31 +08:00
routes fix: batch directory-modal project fetch instead of N+1 getProject burst 2026-07-20 11:30:22 -07:00
index.ts feat: add library and refresh shared table UI 2026-07-16 20:07:12 +08:00