setting default db pool and verflow sizes

This commit is contained in:
msramalho
2025-02-13 00:07:15 +00:00
parent 4341b80dfc
commit 8b0f0023b1

View File

@@ -9,7 +9,13 @@ from app.shared.settings import get_settings
@lru_cache
def make_engine(database_url: str):
engine = create_engine(database_url, connect_args={"check_same_thread": False})
engine = create_engine(
database_url,
connect_args={"check_same_thread": False},
pool_size=15, # Increase pool size
max_overflow=20, # Allow more temporary connections
pool_recycle=1800 # Recycle connections every 30 minutes
)
@event.listens_for(engine, "connect")
def set_sqlite_pragma(conn, _) -> None:
@@ -37,6 +43,7 @@ def get_db_dependency():
with get_db() as db:
yield db
def wal_checkpoint():
# WAL checkpointing, make sure the .sqlite file receives the latest changes
# to be called at startup as it halts writes