Skip to content

refactor(api): convert Depends(get_db) to db: Any = None across API endpoints to release connection pool early - #841

Merged
yaojin3616 merged 1 commit into
mainfrom
refactor/clean-manual-tenant-id
Aug 6, 2026
Merged

refactor(api): convert Depends(get_db) to db: Any = None across API endpoints to release connection pool early#841
yaojin3616 merged 1 commit into
mainfrom
refactor/clean-manual-tenant-id

Conversation

@yaojin3616

Copy link
Copy Markdown
Collaborator

Summary of Changes

  • Connection Pool Optimization & Disentanglement: Refactored long-lived db: AsyncSession = Depends(get_db) FastAPI parameter injections across 35 API endpoint files to optional db: Any = None.
  • Prevent Connection Starvation: By disentangling Request-level DB session allocation from the API routes, DB connections are no longer held alive for the entire duration of HTTP requests (which may involve long-running LLM inferences, streaming, or external RPCs). Connections are now acquired on-demand within narrow DAO calls and released immediately back to the pool.
  • Backward & Unit Test Compatibility: Preserves optional db: Any = None parameter for Unit Tests mocking and explicit session passing.
  • Verification: All 2141 unit tests passed cleanly and scripts/arch-guard.sh constitutional check passed.

@yaojin3616
yaojin3616 merged commit 2b303a0 into main Aug 6, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant