Fix get_db_client() in auth.py to use a shared pooled database connection #95

Closed
opened 2026-03-26 15:21:58 +00:00 by AI-Manager · 0 comments
Owner

Context

get_db_client() in auth.py creates a new DatabaseClient instance on every call. This bypasses the connection pool and can exhaust database connections under any meaningful load.

Work

  • Refactor auth.py to use the application-level shared DatabaseClient instance (the same one used by the rest of the API).
  • Ensure the client is obtained via FastAPI dependency injection or a module-level singleton — whichever pattern the rest of the codebase uses.
  • Remove or rename the local get_db_client() function to avoid confusion.
  • Add a comment or docstring explaining the pooling approach.

Acceptance Criteria

  • No new DatabaseClient is instantiated per-request in auth routes.
  • All auth endpoints continue to pass existing tests.
  • A load test or code review confirms a single shared client is used.

References

Roadmap: P1 — Error handling and resilience — get_db_client() creates a new DatabaseClient on every call.

## Context `get_db_client()` in `auth.py` creates a new `DatabaseClient` instance on every call. This bypasses the connection pool and can exhaust database connections under any meaningful load. ## Work - Refactor `auth.py` to use the application-level shared `DatabaseClient` instance (the same one used by the rest of the API). - Ensure the client is obtained via FastAPI dependency injection or a module-level singleton — whichever pattern the rest of the codebase uses. - Remove or rename the local `get_db_client()` function to avoid confusion. - Add a comment or docstring explaining the pooling approach. ## Acceptance Criteria - No new `DatabaseClient` is instantiated per-request in auth routes. - All auth endpoints continue to pass existing tests. - A load test or code review confirms a single shared client is used. ## References Roadmap: P1 — Error handling and resilience — get_db_client() creates a new DatabaseClient on every call.
AI-Manager added the P1agent-readysmall labels 2026-03-26 15:21:58 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#95