From 6c382ae60c414e974ef944e7cc91df5e6860c380 Mon Sep 17 00:00:00 2001 From: Thomas Oettli Date: Fri, 23 Jan 2026 21:15:42 +0100 Subject: [PATCH] Use MariaDB connection pooling instead of single connection --- src/ddns_service/config.py | 1 + src/ddns_service/models.py | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ddns_service/config.py b/src/ddns_service/config.py index 7f23ed6..c21301b 100644 --- a/src/ddns_service/config.py +++ b/src/ddns_service/config.py @@ -144,6 +144,7 @@ def load_config(config_path): cfg.setdefault("database", {}) cfg["database"].setdefault("backend", "sqlite") + cfg["database"].setdefault("pool_size", 5) cfg.setdefault("dns_service", {}) cfg["dns_service"].setdefault("dns_server", "127.0.0.1") diff --git a/src/ddns_service/models.py b/src/ddns_service/models.py index b966acb..99330aa 100644 --- a/src/ddns_service/models.py +++ b/src/ddns_service/models.py @@ -14,9 +14,9 @@ from peewee import ( ForeignKeyField, IntegerField, Model, - MySQLDatabase, SqliteDatabase, ) +from playhouse.pool import PooledMySQLDatabase # Database proxy (initialized later with actual backend) db = DatabaseProxy() @@ -124,12 +124,13 @@ def init_database(config: dict): logging.debug(f"Database backend: SQLite path={db_path}") elif backend == "mariadb": - actual_db = MySQLDatabase( + actual_db = PooledMySQLDatabase( config["database"]["database"], host=config["database"].get("host", "localhost"), port=config["database"].get("port", 3306), user=config["database"]["user"], password=config["database"]["password"], + max_connections=config["database"].get("pool_size", 5), ) db.initialize(actual_db) db_name = config['database']['database']