Skip to content

fix: speed up admin accounts page + PgBouncer statement_timeout fix#1988

Merged
bokelley merged 5 commits intomainfrom
bokelley/fast-admin-accounts
Apr 8, 2026
Merged

fix: speed up admin accounts page + PgBouncer statement_timeout fix#1988
bokelley merged 5 commits intomainfrom
bokelley/fast-admin-accounts

Conversation

@bokelley
Copy link
Copy Markdown
Contributor

@bokelley bokelley commented Apr 7, 2026

Summary

Root Cause (outage)

PR #1983 set statement_timeout via options: '-c statement_timeout=30000' in the Pool constructor. PgBouncer (used by Fly.io managed Postgres) rejects startup parameters, causing connection failures. Fixed by issuing SET statement_timeout = 30000 after connection establishment.

Test plan

  • 563 unit tests pass
  • TypeScript compiles clean
  • Local Docker Compose: all admin account views return 200
  • Verify /admin/accounts loads faster in production
  • Verify no more connection failures in Fly.io logs

Supersedes #1989 (includes Emma's PgBouncer fix with retry logic removed — the root cause fix makes retries unnecessary).

🤖 Generated with Claude Code

bokelley and others added 2 commits April 7, 2026 17:53
Replace per-row LATERAL joins with pre-aggregated subqueries for
community points, batch subsidiary counts in post-fetch phase, and
add covering indexes for the hot paths.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The startup parameter `options: '-c statement_timeout=30000'` from #1983
is rejected by PgBouncer (Fly.io managed Postgres). Move to a
pool.on("connect") handler that issues SET after connection establishment.

Also parallelizes the two independent queries in findStaleSeatRequests().

Co-Authored-By: Emma Mulitz <emulitz@scope3.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@bokelley bokelley changed the title fix: speed up admin accounts page with query optimizations fix: speed up admin accounts page + PgBouncer statement_timeout fix Apr 8, 2026
bokelley and others added 3 commits April 8, 2026 04:20
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
REFRESH MATERIALIZED VIEW CONCURRENTLY cannot run inside a transaction
block. Remove the BEGIN/COMMIT wrapper and use a plain SET (not LOCAL)
for the 120s timeout override on a dedicated client.

Also align the detail endpoint's subsidiary_count to exclude parent orgs
(orgs whose email_domain equals the house_domain), matching the list
endpoint's batched query.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Merge needs_attention + hot into a single query so the community
  points CTE runs once instead of twice
- Dead session cache: evict oldest entry at capacity instead of
  silently dropping new entries
- Document the pool.on("connect") async race window for statement_timeout

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@bokelley bokelley merged commit 0c49812 into main Apr 8, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant