forked from 0xWheatyz/SPARC
Refactor get_db_client() in auth.py to use a shared connection pool #1268
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
get_db_client()inauth.pyinstantiates a newDatabaseClienton every call instead of reusing the application-level pooled client. Under load this exhausts available database connections.Roadmap reference: P1 - Error handling and resilience
What to do
DatabaseClientconstruction fromget_db_client().DatabaseClient(or FastAPI dependency) that the rest of the application uses.Depends()pattern so it is testable.Acceptance criteria
DatabaseClientinstance exists per application lifetime (or one per request via the pool, not one per auth check).Triage: Already Implemented
This refactor is fully implemented in the current codebase on
main:SPARC/auth.pyuses a module-level singleton_db_client(line 150) initialized viainit_db_client()at app startup.get_db_client()returns the shared instance, with a lazy-init fallback for testing (lines 168-178).close_db_client()cleanly shuts down the connection at app shutdown (lines 160-165).SPARC/api.pycallsinit_db_client()andclose_db_client()in the lifespan handler.No more per-request
DatabaseClientinstantiation. Closing as completed.