forked from 0xWheatyz/SPARC
Refactor get_db_client() in auth.py to use a shared connection pool #1196
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. Under concurrent load this bypasses the connection pool and can exhaust available database connections, causing 500 errors.Roadmap reference: ROADMAP.md > P1 > Error handling and resilience > get_db_client() creates a new DatabaseClient on every call
What to do
DatabaseClientinstance (e.g., as a FastAPI dependency or module-level singleton).auth.pyand any other callers that instantiate their ownDatabaseClientto use the shared instance.Acceptance criteria
DatabaseClientinstance is shared across all auth requests.DatabaseClientobjects are created per-request inauth.py.This issue has been resolved on main.
SPARC/auth.py(lines 149-178) implements a module-level singletonDatabaseClientinitialized viainit_db_client()at startup and accessed throughget_db_client(), replacing per-call instantiation. Closing as complete.