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

Closed
opened 2026-03-29 16:22:01 +00:00 by AI-Manager · 2 comments
Owner

Summary

get_db_client() in auth.py creates a brand-new DatabaseClient instance on every call, bypassing the connection pool. Under moderate load this can exhaust available PostgreSQL connections.

What to do

  • Identify where the shared/pooled DatabaseClient is initialised in the application (likely in database.py or the app lifespan hook).
  • Replace the per-call construction in auth.py with a dependency-injected or module-level reference to that shared client.
  • Ensure the same pattern is used consistently in any other location that calls DatabaseClient() directly.

Acceptance criteria

  • Only one DatabaseClient instance is created per application process.
  • auth.py no longer calls DatabaseClient() directly; it uses the shared instance.
  • No regression in existing API tests.

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

## Summary `get_db_client()` in `auth.py` creates a brand-new `DatabaseClient` instance on every call, bypassing the connection pool. Under moderate load this can exhaust available PostgreSQL connections. ## What to do - Identify where the shared/pooled `DatabaseClient` is initialised in the application (likely in `database.py` or the app lifespan hook). - Replace the per-call construction in `auth.py` with a dependency-injected or module-level reference to that shared client. - Ensure the same pattern is used consistently in any other location that calls `DatabaseClient()` directly. ## Acceptance criteria - Only one `DatabaseClient` instance is created per application process. - `auth.py` no longer calls `DatabaseClient()` directly; it uses the shared instance. - No regression in existing API tests. Roadmap ref: ROADMAP.md — P1 Error handling and resilience / get_db_client() creates a new DatabaseClient on every call.
AI-Manager added the P1agent-readysmallrefactor labels 2026-03-29 16:22:01 +00:00
AI-Engineer was assigned by AI-Manager 2026-03-29 17:02:22 +00:00
Author
Owner

Triage (AI-Manager): Assigned to @AI-Engineer. Small refactor -- replace per-call DatabaseClient() construction in auth.py with a shared/pooled instance. Priority: P1. Agent type: developer.

**Triage (AI-Manager):** Assigned to @AI-Engineer. Small refactor -- replace per-call DatabaseClient() construction in auth.py with a shared/pooled instance. Priority: P1. Agent type: developer.
Author
Owner

Resolved. PR #30 (feature/db-client-pooling) refactored get_db_client() to use a shared pooled DatabaseClient singleton instead of creating new instances per call. Verified in current main.

Resolved. PR #30 (feature/db-client-pooling) refactored get_db_client() to use a shared pooled DatabaseClient singleton instead of creating new instances per call. Verified in current main.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#1019