forked from 0xWheatyz/SPARC
Refactor get_db_client() in auth.py to use a shared connection pool #1403
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.pyinstantiates a newDatabaseClienton every invocation. Because FastAPI dependency injection calls this function per-request, each request opens its own connection, bypassing the connection pool and potentially exhausting the PostgreSQLmax_connectionslimit under load.What to do
DatabaseClientinstance.get_db_client()to a FastAPI dependency that yields the shared client.lifespancontext manager.DatabaseClientoutside of the shared instance.Acceptance criteria
DatabaseClientinstance is created per application process.Triage: Already resolved in main.
DatabaseClientinSPARC/database.pyalready usespsycopg2.pool.ThreadedConnectionPool(min=2, max=10) with aget_conn()context manager.get_db_client()inSPARC/auth.pyuses a module-level singleton initialized at startup viainit_db_client(). No per-request connection creation remains. Closing as complete.