forked from 0xWheatyz/SPARC
Refactor get_db_client() in auth.py to use a shared connection pool #1378
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Background
Roadmap item: P1 Error handling and resilience — get_db_client() bypasses connection pool
get_db_client()inauth.pyconstructs a freshDatabaseClienton every invocation. Each client opens its own database connection, bypassing the connection pool. Under load this can exhaust the PostgreSQLmax_connectionslimit and cause request failures.Task
DatabaseClientis created (likely indatabase.pyor the app startup).get_db_client()to return a reference to the shared, pooled client rather than creating a new one.lifespan.Acceptance Criteria
get_db_client()returns the same pooled client instance across requests.DatabaseClient(...)construction happens inside per-request paths inauth.py.Reference
See ROADMAP.md § P1 Error handling and resilience.
Resolved by PR #30 (merged).
get_db_client()inauth.pynow uses a shared module-level singletonDatabaseClient, initialized at startup viainit_db_client()and cleaned up viaclose_db_client().