forked from 0xWheatyz/SPARC
Fix get_db_client() in auth.py to use a shared pooled connection instead of creating a new client per call #42
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?
Problem
get_db_client()inauth.pycreates a newDatabaseClientinstance on every invocation. Because this function is called on every authenticated request, each request opens a fresh database connection that bypasses the connection pool. Under moderate load this can exhaust available Postgres connections.Task
auth.pyso thatget_db_client()returns a reference to a single shared (or module-level)DatabaseClientinstance, or correctly integrates with the existing pooled client used elsewhere in the application.yieldif appropriate).get_db_client()return the same (or a pooled) connection and do not open unbounded new connections.Acceptance Criteria
References
Roadmap: P1 -- Error handling and resilience -- get_db_client() creates a new DatabaseClient on every call.
Closing: Already implemented in PR #30 (refactor(db): shared pooled DatabaseClient singleton). auth.py now uses a singleton pattern for the database client.