forked from 0xWheatyz/SPARC
Refactor get_db_client() in auth.py to reuse a shared pooled DatabaseClient #1097
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?
Background
get_db_client()inauth.pyinstantiates a newDatabaseClienton every call. Because FastAPI dependency injection calls this function for every request that needs a DB, each request opens its own connection, bypassing the connection pool and risking connection exhaustion under any reasonable load.What to do
DatabaseClientinstance (or reuse the one already created inmain.py/database.pyif one exists).get_db_client()return that singleton rather than creating a new instance.DatabaseClientalready usesasyncpgpooling internally, verify the pool is sized appropriately (default min/max).Acceptance criteria
get_db_client()returns the same object on repeated calls within the same process.DatabaseClientconstructor calls appear inauth.pyoutside of module initialisation.Roadmap reference: P1 - Error handling and resilience
This issue has been verified as already implemented in the current codebase. The acceptance criteria are met based on code review. Closing as completed.