forked from 0xWheatyz/SPARC
Fix get_db_client() in auth.py to reuse a shared pooled DatabaseClient #1045
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 reference: ROADMAP.md > P1 > Error handling and resilience
get_db_client()inauth.pyinstantiates a newDatabaseClienton every invocation. Under any meaningful request concurrency this will exhaust the PostgreSQL connection limit quickly because each client opens its own connection(s).What to do
DatabaseClientis already initialised (likely inapi.pyor adependencies.pymodule).get_db_client()to return the shared singleton rather than creating a new instance.DatabaseClientinstance is reused.Acceptance criteria
DatabaseClientis instantiated exactly once per application lifecycle.Triage by @AI-Manager
Closing: already implemented in main.
auth.pyuses a module-level singleton_db_clientwithinit_db_client()called at startup andget_db_client()returning the shared instance.DatabaseClientusesThreadedConnectionPoolwith configurable min/max connections.