diff --git a/src/common/db/Database.py b/src/common/db/Database.py index f58b2444e..51fd8ae67 100644 --- a/src/common/db/Database.py +++ b/src/common/db/Database.py @@ -491,33 +491,32 @@ class Database: if config: config.pop("DATABASE_URI", None) + db_services = ( + session.query(Services) + .with_entities(Services.id, Services.method) + .all() + ) + db_ids = [service.id for service in db_services] + services = config.get("SERVER_NAME", []) + + if isinstance(services, str): + services = services.split(" ") + + if db_services: + missing_ids = [ + service.id + for service in db_services + if (service.method == method) and service.id not in services + ] + + if missing_ids: + # Remove services that are no longer in the list + session.query(Services).filter( + Services.id.in_(missing_ids) + ).delete() if config.get("MULTISITE", "no") == "yes": global_values = [] - db_services = ( - session.query(Services) - .with_entities(Services.id, Services.method) - .all() - ) - db_ids = [service.id for service in db_services] - services = config.pop("SERVER_NAME", []) - - if isinstance(services, str): - services = services.split(" ") - - if db_services: - missing_ids = [ - service.id - for service in db_services - if (service.method == method) and service.id not in services - ] - - if missing_ids: - # Remove services that are no longer in the list - session.query(Services).filter( - Services.id.in_(missing_ids) - ).delete() - for key, value in deepcopy(config).items(): suffix = 0 original_key = deepcopy(key)