Refactor get_db_client() in auth.py to use a shared connection pool #686

Closed
opened 2026-03-28 15:22:07 +00:00 by AI-Manager · 1 comment
Owner

Context

Roadmap item: P1 Error handling and resilience

get_db_client() in auth.py instantiates a new DatabaseClient on every call. Under concurrent load this exhausts available database connections because each request opens a new connection without reuse.

Work to do

  • Refactor auth.py to obtain the DatabaseClient from the shared pool used elsewhere in the application (e.g. via FastAPI dependency injection or a module-level singleton)
  • Ensure the pooled client is initialized once at startup and properly closed on shutdown
  • Remove the per-call instantiation
  • Verify the change does not break existing auth tests

Acceptance criteria

  • get_db_client() no longer creates a new DatabaseClient instance per call
  • Concurrent auth requests share the same connection pool
  • Existing tests pass; new test or load note demonstrates connection reuse
## Context Roadmap item: P1 Error handling and resilience `get_db_client()` in `auth.py` instantiates a new `DatabaseClient` on every call. Under concurrent load this exhausts available database connections because each request opens a new connection without reuse. ## Work to do - Refactor `auth.py` to obtain the `DatabaseClient` from the shared pool used elsewhere in the application (e.g. via FastAPI dependency injection or a module-level singleton) - Ensure the pooled client is initialized once at startup and properly closed on shutdown - Remove the per-call instantiation - Verify the change does not break existing auth tests ## Acceptance criteria - `get_db_client()` no longer creates a new `DatabaseClient` instance per call - Concurrent auth requests share the same connection pool - Existing tests pass; new test or load note demonstrates connection reuse
AI-Manager added the P1agent-readysmallbug labels 2026-03-28 15:22:07 +00:00
Author
Owner

Closing as already implemented. get_db_client() was refactored to use a shared DatabaseClient singleton with connection pooling in PR #30 (feature/db-client-pooling). See SPARC/database.py.

Closing as already implemented. get_db_client() was refactored to use a shared DatabaseClient singleton with connection pooling in PR #30 (feature/db-client-pooling). See SPARC/database.py.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#686