refactor: Update database service to use pool_size and max_overflow settings

The DatabaseService class in service.py has been updated to use the pool_size and max_overflow settings from the SettingsService. This change allows for better control over the number of connections in the connection pool and the number of connections that can be opened beyond the pool size. The commit also includes necessary modifications to the create_engine function to pass the pool_size and max_overflow parameters.

Note: The commit message has been generated based on the provided code changes and recent commits.
This commit is contained in:
ogabrielluiz 2024-06-03 13:02:49 -03:00
commit 099d44bad0
2 changed files with 14 additions and 2 deletions

View file

@ -20,12 +20,14 @@ from langflow.services.utils import teardown_superuser
if TYPE_CHECKING:
from sqlalchemy.engine import Engine
from langflow.services.settings.manager import SettingsService
class DatabaseService(Service):
name = "database_service"
def __init__(self, database_url: str):
def __init__(self, database_url: str, settings_service: "SettingsService"):
self.settings_service = settings_service
self.database_url = database_url
# This file is in langflow.services.database.manager.py
# the ini is in langflow
@ -41,7 +43,12 @@ class DatabaseService(Service):
connect_args = {"check_same_thread": False}
else:
connect_args = {}
return create_engine(self.database_url, connect_args=connect_args)
return create_engine(
self.database_url,
connect_args=connect_args,
pool_size=self.settings_service.settings.pool_size,
max_overflow=self.settings_service.settings.max_overflow,
)
def __enter__(self):
self._session = Session(self.engine)

View file

@ -67,6 +67,11 @@ class Settings(BaseSettings):
dev: bool = False
database_url: Optional[str] = None
"""Database URL for Langflow. If not provided, Langflow will use a SQLite database."""
pool_size: int = 10
"""The number of connections to keep open in the connection pool. If not provided, the default is 10."""
max_overflow: int = 10
"""The number of connections to allow that can be opened beyond the pool size. If not provided, the default is 10."""
cache_type: str = "async"
remove_api_keys: bool = False
components_path: List[str] = []