fix: speed up admin accounts page + PgBouncer statement_timeout fix#1988
Merged
fix: speed up admin accounts page + PgBouncer statement_timeout fix#1988
Conversation
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>
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
statement_timeoutfrom Pool startupoptionsto a per-connectionSEThandler (supersedes fix: DB connection resilience — retry logic, parallel queries, PgBouncer compat #1989)findStaleSeatRequests()Root Cause (outage)
PR #1983 set
statement_timeoutviaoptions: '-c statement_timeout=30000'in the Pool constructor. PgBouncer (used by Fly.io managed Postgres) rejects startup parameters, causing connection failures. Fixed by issuingSET statement_timeout = 30000after connection establishment.Test plan
Supersedes #1989 (includes Emma's PgBouncer fix with retry logic removed — the root cause fix makes retries unnecessary).
🤖 Generated with Claude Code