Use MariaDB connection pooling instead of single connection
This commit is contained in:
@@ -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")
|
||||
|
||||
@@ -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']
|
||||
|
||||
Reference in New Issue
Block a user