forked from 0xWheatyz/SPARC
Fix get_db_client() to use a shared connection pool instead of creating a new client per call #205
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
auth.pycallsget_db_client()which instantiates a freshDatabaseClienton every invocation. Under concurrent load this bypasses the connection pool, exhausts available database connections, and can cause 500 errors.Roadmap reference: ROADMAP.md > P1 > Error handling and resilience
What to do
get_db_client()(or theDatabaseClientinitialisation) so a single pooled client instance is created at startup and reused across requests.Depends) or a module-level singleton to expose the shared client.Acceptance criteria
DatabaseClientis created per process lifetime (or per pool configuration)./auth/login,/auth/register) continue to work correctly.This issue has already been resolved in the current codebase.
auth.pyuses a module-level_db_clientsingleton initialized viainit_db_client()at startup.get_db_client()returns the singleton, only creating a new client if the singleton is None (lazy fallback). This prevents creating a new database connection on every call.Closing as already implemented.