Improve SQLite performance (#2111)
* tune sqlite upon connection * catch operational error * use wal for journal_mode for faster performance
This commit is contained in:
parent
89faa251ef
commit
ad23cac117
1 changed files with 16 additions and 0 deletions
|
|
@ -9,6 +9,8 @@ from alembic.config import Config
|
|||
from loguru import logger
|
||||
from sqlalchemy import inspect
|
||||
from sqlalchemy.exc import OperationalError
|
||||
from sqlalchemy.engine import Engine
|
||||
from sqlalchemy import event
|
||||
from sqlmodel import Session, SQLModel, create_engine, select, text
|
||||
|
||||
from langflow.services.base import Service
|
||||
|
|
@ -53,6 +55,20 @@ class DatabaseService(Service):
|
|||
max_overflow=self.settings_service.settings.max_overflow,
|
||||
)
|
||||
|
||||
@event.listens_for(Engine, "connect")
|
||||
def on_connection(dbapi_connection, connection_record):
|
||||
from sqlite3 import Connection as sqliteConnection
|
||||
|
||||
if isinstance(dbapi_connection, sqliteConnection):
|
||||
logger.info("sqlite connect listener, setting pragmas")
|
||||
cursor = dbapi_connection.cursor()
|
||||
try:
|
||||
cursor.execute("PRAGMA synchronous = NORMAL")
|
||||
cursor.execute("PRAGMA journal_mode = WAL")
|
||||
cursor.close()
|
||||
except OperationalError as oe:
|
||||
logger.warning("Failed to set PRAGMA: ", {oe})
|
||||
|
||||
def __enter__(self):
|
||||
self._session = Session(self.engine)
|
||||
return self._session
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue