diff --git a/src/db_config.py b/src/db_config.py index 75ee739..8586444 100644 --- a/src/db_config.py +++ b/src/db_config.py @@ -14,9 +14,9 @@ engine = create_async_engine( SQLALCHEMY_DATABASE_URL, - pool_size=15, - max_overflow=15, - pool_timeout=30, + pool_size=30, + max_overflow=20, + pool_timeout=60, ) sync_engine = create_engine(SQLALCHEMY_DATABASE_URL) @@ -96,12 +96,9 @@ async def __aenter__(self): async def __aexit__(self, exc_type, exc_value, traceback): try: - if exc_type is None: - # 2. If NO exception occurred, commit the transaction. + if not self.db.in_transaction() and exc_type is None: await self.db.commit() - else: - # 3. If an exception DID occur, roll back the transaction. + elif not self.db.in_transaction(): await self.db.rollback() finally: - # 4. ALWAYS close the session. await self.db.close()