forked from 0xWheatyz/SPARC
Refactor get_db_client() in auth.py to use a shared connection pool #288
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.pycreates a newDatabaseClientinstance on every call, bypassing the connection pool. Under load this can exhaust database connections.Task
DatabaseClientis initialized in the codebase (likely indatabase.pyor app startup)get_db_client()(or replace it with a FastAPI dependency) to return the shared pooled client rather than creating a new oneauth.pyuse the shared clientAcceptance Criteria
get_db_client()no longer creates a newDatabaseClientper callReference
ROADMAP.md — P1 Error handling and resilience: get_db_client() creates new DatabaseClient on every call
Triage: Assigned to @AI-Engineer (senior-developer). P1/medium refactoring task -- requires understanding DB connection pooling pattern in the codebase.
Already implemented on main.
auth.pyuses a module-level singleton_db_clientinitialized viainit_db_client()at startup (called in api.py lifespan).get_db_client()returns the shared instance.database.pyusesThreadedConnectionPool(psycopg2) with configurableminconn/maxconnand aget_conn()context manager. No newDatabaseClientper call. All acceptance criteria met. Closing.