Coverage for src/local_deep_research/database/pool_config.py: 100%

4 statements  

« prev     ^ index     » next       coverage.py v7.16.0, created at 2026-09-06 15:42 +0000

1"""Shared SQLAlchemy connection pool configuration constants.""" 

2 

3# Per-user encrypted-database pool sizing. See ADR-0004 for why 20/40: 

4# inject_current_user() opens a session on essentially every request, so a 

5# small pool is exhausted by ordinary page loads. 

6# 

7# These are exported rather than inlined because the web layer needs to 

8# reason about the same numbers: sync routes retain one connection per AnyIO 

9# worker thread (see the threadpool sizing check in web/fastapi_app.py), so 

10# a worker pool larger than POOL_SIZE + MAX_OVERFLOW is a misconfiguration. 

11POOL_SIZE = 20 

12MAX_OVERFLOW = 40 

13 

14# Validate connections before checkout (detects stale/broken connections) 

15POOL_PRE_PING = True 

16 

17# Recycle connections after 1 hour to release stale file handles. 

18# SQLite reopens are cheap (no network roundtrip), so a shorter 

19# interval reduces the window for WAL handle accumulation. 

20# See ADR-0004. 

21POOL_RECYCLE_SECONDS = 3600