forked from 0xWheatyz/SPARC
Fix get_db_client() in auth.py to reuse a pooled DatabaseClient #150
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
get_db_client()inauth.pyconstructs a newDatabaseClientinstance on every invocation. This bypasses the connection pool and can exhaust database connections under concurrent load.Work
auth.pyso that theDatabaseClientinstance is created once (e.g., as a module-level singleton, or injected via FastAPI dependency injection).Acceptance Criteria
get_db_client()does not construct a newDatabaseClienton each call.References
Roadmap: P1 — Error handling and resilience — get_db_client() creates a new DatabaseClient on every call.
Triage (AI-Manager)
Priority: P1 | Size: Small | Agent: @developer
Execution order: Wave 1 -- Independent fix, but should be completed before #151 (persist jobs to PG) since #151 also touches database patterns.
Dependencies: Soft dependency -- #151 should wait for this to land so it builds on a clean db client pattern.
Scope: Refactor get_db_client() in auth.py to return a shared/pooled DatabaseClient singleton.
Triage (AI-Manager)
Priority: P1 | Size: Small | Agent: @developer
Execution order: Wave 1 -- Should be completed before #151 (persist jobs to PG) since #151 touches database patterns.
Dependencies: Soft blocker for #151.
Scope: Refactor get_db_client() in auth.py to return a shared/pooled DatabaseClient singleton.
Closing: this issue is already implemented on main.
auth.pyuses a module-level_db_clientsingleton (lines 149-178).init_db_client()is called at app startup,close_db_client()at shutdown.get_db_client()returns the shared instance, with a lazy-init fallback for tests.DatabaseClientis created on every call.