Use MariaDB connection pooling instead of single connection

This commit is contained in:
2026-01-23 21:15:42 +01:00
parent 2381d2e1d2
commit 6c382ae60c
2 changed files with 4 additions and 2 deletions

View File

@@ -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")

View File

@@ -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']