mirror of
https://pagure.io/fm-orchestrator.git
synced 2026-07-17 11:30:19 +08:00
Make db_session singleton
Please note that this patch does not change the use of database session in MBS. So, in the frontend, the database session is still managed by Flask-SQLAlchemy, that is the db.session. And the backend, running event handlers, has its own database session created from SQLAclehmy session API directly. This patch aims to reduce the number of scoped_session created when call original function make_db_session. For technical detailed information, please refer to SQLAlchemy documentation Contextual/Thread-local Sessions. As a result, a global scoped_session is accessible from the code running inside backend, both the event handlers and functions called from handlers. The library code shared by frontend and backend, like resolvers, has no change. Similarly, db.session is only used to recreate database for every test. Signed-off-by: Chenxiong Qi <cqi@redhat.com>
This commit is contained in:
@@ -8,6 +8,7 @@ import module_build_service.resolver
|
||||
|
||||
from tests import init_data
|
||||
|
||||
from module_build_service.db_session import db_session
|
||||
from module_build_service.builder import GenericBuilder
|
||||
from mock import patch
|
||||
|
||||
@@ -18,7 +19,7 @@ class TestGenericBuilder:
|
||||
|
||||
@patch("module_build_service.resolver.DBResolver")
|
||||
@patch("module_build_service.builder.base.GenericResolver")
|
||||
def test_default_buildroot_groups_cache(self, generic_resolver, resolver, db_session):
|
||||
def test_default_buildroot_groups_cache(self, generic_resolver, resolver):
|
||||
mbs_groups = {"buildroot": [], "srpm-buildroot": []}
|
||||
|
||||
resolver = mock.MagicMock()
|
||||
|
||||
Reference in New Issue
Block a user