Fix database not providing the right SERVER_NAME setting value

This commit is contained in:
Théophile Diot 2023-05-10 13:10:47 -04:00
parent cf26d7aa22
commit 8a308b1a88
No known key found for this signature in database
GPG Key ID: E752C80DB72BB014
1 changed files with 13 additions and 18 deletions

View File

@ -366,7 +366,10 @@ class Database:
.all()
)
db_ids = [service.id for service in db_services]
services = config.get("SERVER_NAME", "").split(" ")
services = config.pop("SERVER_NAME", [])
if isinstance(services, str):
services = services.split(" ")
if db_services:
missing_ids = [
@ -376,13 +379,14 @@ class Database:
]
if missing_ids:
# Remove plugins that are no longer in the list
# 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)
if self.suffix_rx.search(key):
suffix = int(key.split("_")[-1])
key = key[: -len(str(suffix)) - 1]
@ -475,8 +479,8 @@ class Database:
Services_settings.method: method,
}
)
elif f"{key}_{suffix}" not in global_values:
global_values.append(f"{key}_{suffix}")
elif setting and original_key not in global_values:
global_values.append(original_key)
global_value = (
session.query(Global_values)
.with_entities(
@ -489,9 +493,6 @@ class Database:
.first()
)
if not setting:
continue
if global_value is None:
if value == setting.default or (
not value.strip() and setting.default is None
@ -569,11 +570,6 @@ class Database:
)
if global_value is None:
if value == setting.default or (
not value.strip() and setting.default is None
):
continue
to_put.append(
Global_values(
setting_id=key,
@ -627,12 +623,6 @@ class Database:
to_put = []
endl = "\n"
for custom_config in custom_configs:
# config = {
# "data": custom_config["value"].replace("\\\n", "\n").encode("utf-8")
# if isinstance(custom_config["value"], str)
# else custom_config["value"].replace(b"\\\n", b"\n"),
# "method": method,
# }
config = {
"data": custom_config["value"].encode("utf-8")
if isinstance(custom_config["value"], str)
@ -806,6 +796,11 @@ class Database:
}
)
servers = " ".join(service.id for service in session.query(Services).all())
config["SERVER_NAME"] = (
servers if methods is False else {"value": servers, "method": "default"}
)
return config
def get_custom_configs(self) -> List[Dict[str, Any]]: