forked from 0xWheatyz/SPARC
Refactor get_db_client() to use a shared pooled connection #640
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 item: P1 Error Handling and Resilience
get_db_client()inauth.pycreates a newDatabaseClienton every call. This bypasses the connection pool and can exhaust database connections under load.What to do
DatabaseClientinstance is created in the codebase (likely indatabase.pyormain.py)auth.pywith a dependency on the shared pooled client (e.g. via FastAPIDepends(get_db))Acceptance criteria
auth.pyno longer creates aDatabaseClientinsideget_db_client()Closing as already implemented.
SPARC/database.pyusespsycopg2.pool.ThreadedConnectionPoolwith configurable min/max connections and a context manager that checks out and returns connections properly.