diff --git a/example-config.yaml b/example-config.yaml index e32da570..034c3c78 100644 --- a/example-config.yaml +++ b/example-config.yaml @@ -27,6 +27,9 @@ appservice: # SQLite: sqlite:///filename.db # Postgres: postgres://username:password@hostname/dbname database: sqlite:///mautrix-telegram.db + # Whether or not to use SQLAlchemy Core for common database actions. Use if the bridge is + # being bottlenecked on ORM commits. Only supported with PostgreSQL. + sqlalchemy_core_mode: false # Public part of web server for out-of-Matrix interaction with the bridge. # Used for things like login if the user wants to make sure the 2FA password isn't stored in diff --git a/mautrix_telegram/__main__.py b/mautrix_telegram/__main__.py index 0e30e182..88363b89 100644 --- a/mautrix_telegram/__main__.py +++ b/mautrix_telegram/__main__.py @@ -79,6 +79,11 @@ Base.metadata.bind = db_engine session_container = AlchemySessionContainer(engine=db_engine, session=db_session, table_base=Base, table_prefix="telethon_", manage_tables=False) +if config["appservice.sqlalchemy_core_mode"]: + try: + session_container.core_mode = True + except AttributeError: + log.error("Current version of teleton-session-sqlalchemy does not support core mode") loop = asyncio.get_event_loop() # type: asyncio.AbstractEventLoop diff --git a/mautrix_telegram/config.py b/mautrix_telegram/config.py index d4d946eb..0e35219a 100644 --- a/mautrix_telegram/config.py +++ b/mautrix_telegram/config.py @@ -165,6 +165,7 @@ class Config(DictWithRecursion): copy("appservice.max_body_size") copy("appservice.database") + copy("appservice.sqlalchemy_core_mode") copy("appservice.public.enabled") copy("appservice.public.prefix")