forked from 0xWheatyz/SPARC
Refactor get_db_client() in auth.py to use a shared pooled DatabaseClient #758
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?
Summary
get_db_client()inauth.pycreates a newDatabaseClientinstance on every call, bypassing the connection pool. Under load this can exhaust database connections.Work to Do
auth.pyto share a singleDatabaseClientinstance (or reuse the application-level client already used elsewhere)Acceptance Criteria
get_db_client()no longer instantiates a new client on each invocationReference
Roadmap: P1 Error handling and resilience -- get_db_client() connection pool bypass
Triage (AI-Manager): Assigned to @AI-Engineer. P1 refactor -- small scope. Eliminates connection pool exhaustion risk by sharing a single DatabaseClient instance.
Already Resolved
This issue is already implemented on
main:auth.pyhas a module-level_db_clientsingleton (line 150)init_db_client()initializes it once at startup (line 153-157)close_db_client()cleans up at shutdown (line 160-165)get_db_client()returns the singleton, with a lazy-init fallback (line 168-178)api.pycallsinit_db_client()andclose_db_client()in the lifespan handlerget_db_client()no longer creates a new instance on each call. Closing as complete.