配置生成逻辑优化
This commit is contained in:
@@ -258,24 +258,20 @@ External_Resources_Manager::External_Resources_Manager()
|
||||
register_external_resource(make_opensky_flightdata_api_resource());
|
||||
}
|
||||
|
||||
void External_Resources_Manager::from_json(const Psc::JSON* that_json, bool not_exist_use_default_value)
|
||||
{
|
||||
if (!that_json)
|
||||
return;
|
||||
void External_Resources_Manager::from_json(const Psc::JSON* that_json) {
|
||||
if (that_json == nullptr || that_json->valueType != Psc::Object)
|
||||
throw Psc::json_assign_error(std::make_error_code(std::errc::invalid_argument), "external_database");
|
||||
const auto list = that_json->get("list");
|
||||
if (!list)
|
||||
return;
|
||||
if (list == nullptr || list->valueType != Psc::Array)
|
||||
throw Psc::json_assign_error(std::make_error_code(std::errc::invalid_argument), "external_database.list");
|
||||
std::lock_guard lock(mtx_);
|
||||
for (const auto& config : list->children)
|
||||
{
|
||||
const auto name = config.try_get_string("name");
|
||||
if (!name)
|
||||
continue;
|
||||
for (const auto& resource : resources_)
|
||||
{
|
||||
if (resource->name != *name)
|
||||
for (const auto& config : list->children) {
|
||||
External_Resources_Data parsed;
|
||||
parsed.from_base_json(&config);
|
||||
for (const auto& resource : resources_) {
|
||||
if (resource->name != parsed.name)
|
||||
continue;
|
||||
resource->init(&config);
|
||||
static_cast<External_Resources_Data&>(*resource) = std::move(parsed);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ public:
|
||||
[[nodiscard]] std::optional<External_Database_Row>
|
||||
query_one(SQLite::Database& db, const std::vector<std::string>& primary_key_values) const;
|
||||
void init(const Psc::JSON* that_json) {
|
||||
External_Resources_Data::from_base_json(that_json, false);
|
||||
External_Resources_Data::from_base_json(that_json);
|
||||
}
|
||||
[[nodiscard]] Psc::JSON to_json() const {
|
||||
return External_Resources_Data::to_base_json();
|
||||
@@ -78,7 +78,7 @@ public:
|
||||
using Row_Callback = std::function<void(std::exception_ptr, std::optional<External_Database_Row>)>;
|
||||
using Row_Map_Callback = std::function<void(std::exception_ptr, External_Database_Row_Map)>;
|
||||
External_Resources_Manager();
|
||||
void from_json(const Psc::JSON* that_json, bool not_exist_use_default_value);
|
||||
void from_json(const Psc::JSON* that_json);
|
||||
[[nodiscard]] Psc::JSON to_base_json() const;
|
||||
void server(Global* g);
|
||||
void ensure_sqlite_db_loaded(std::string_view path);
|
||||
|
||||
Reference in New Issue
Block a user