forked from 0xWheatyz/SPARC
Fix get_db_client() in auth.py to reuse a shared pooled database connection #737
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?
Context
Roadmap reference: P1 - Error handling and resilience
get_db_client()inauth.pycreates a newDatabaseClientinstance on every call. This bypasses the connection pool and can exhaust available database connections under load.What to do
auth.pyto accept the sharedDatabaseClient(or session factory) as a FastAPI dependency rather than constructing it inlineDatabaseClientconstruction from withinget_db_client()Acceptance criteria
get_db_client()no longer instantiates a newDatabaseClienton each callResolved.
auth.pynow uses a module-level singleton_db_clientinitialized viainit_db_client()at app startup.get_db_client()returns the shared instance. No per-callDatabaseClientconstruction remains in normal flow.