From 1b260981a806bbc14223d2f8aaba38cf56b6446d Mon Sep 17 00:00:00 2001 From: Aurélien Bompard Date: Jul 11 2025 07:36:48 +0000 Subject: Make the database's pool_recycle option configurable Signed-off-by: Aurélien Bompard --- diff --git a/doc/configuration.rst b/doc/configuration.rst index 047e960..cb015d2 100644 --- a/doc/configuration.rst +++ b/doc/configuration.rst @@ -1764,6 +1764,18 @@ Defaults to: ]) +DB_POOL_RECYCLE +~~~~~~~~~~~~~~~ + +This is the lifetime of a database connection in the connection pool, in seconds. +For more details, refer to `SQLAlchemy's documentation`_ on the ``pool_recycle`` +option. + +Defaults to: ``3600`` (1 hour) + +.. _SQLAlchemy's documentation: https://docs.sqlalchemy.org/en/21/core/engines.html#sqlalchemy.create_engine.params.pool_recycle + + SSH_KEYS_USERNAME_LOOKUP ~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/pagure/default_config.py b/pagure/default_config.py index ec8ae2a..d5bcb59 100644 --- a/pagure/default_config.py +++ b/pagure/default_config.py @@ -577,3 +577,5 @@ PR_WARN_CHARACTERS = set( chr(0x2069), ] ) + +DB_POOL_RECYCLE = 3600 diff --git a/pagure/lib/model_base.py b/pagure/lib/model_base.py index 4aaa00e..8008a31 100644 --- a/pagure/lib/model_base.py +++ b/pagure/lib/model_base.py @@ -14,6 +14,9 @@ import sqlalchemy from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import scoped_session, sessionmaker +from pagure.config import config as pagure_config + + CONVENTION = { "ix": "ix_%(table_name)s_%(column_0_label)s", # Checks are currently buggy and prevent us from naming them correctly @@ -31,7 +34,7 @@ BASE = declarative_base( SESSIONMAKER = None -def create_session(db_url=None, debug=False, pool_recycle=3600): +def create_session(db_url=None, debug=False, pool_recycle=None): """Create the Session object to use to query the database. :arg db_url: URL used to connect to the database. The URL contains @@ -44,6 +47,7 @@ def create_session(db_url=None, debug=False, pool_recycle=3600): """ global SESSIONMAKER + pool_recycle = pool_recycle or pagure_config["DB_POOL_RECYCLE"] if SESSIONMAKER is None or ( db_url and db_url != ("{}".format(SESSIONMAKER.kw["bind"].engine.url))