mirror of
https://github.com/anope/anope.git
synced 2026-06-28 04:16:37 +02:00
Fix loading databases in db_json.
This commit is contained in:
@@ -201,6 +201,22 @@ private:
|
||||
CreateBackup(backupdir, dbpath, monthly_backups, "%Y-%m", "\?\?\?\?-\?\?");
|
||||
}
|
||||
|
||||
void LoadType(Serialize::Type *s_type, yyjson_mut_val *data)
|
||||
{
|
||||
auto *entries = yyjson_mut_obj_get(data, s_type->GetName().c_str());
|
||||
if (!entries || !yyjson_mut_is_arr(entries))
|
||||
return;
|
||||
|
||||
Log(LOG_DEBUG) << "Loading " << yyjson_mut_arr_size(entries) << " " << s_type->GetName() << " records";
|
||||
size_t idx, max;
|
||||
yyjson_mut_val *elem;
|
||||
yyjson_mut_arr_foreach(entries, idx, max, elem)
|
||||
{
|
||||
Data ld(elem);
|
||||
s_type->Unserialize(nullptr, ld);
|
||||
}
|
||||
}
|
||||
|
||||
DBPair ReadDatabase(const Anope::string &dbname)
|
||||
{
|
||||
yyjson_read_err errmsg;
|
||||
@@ -269,19 +285,11 @@ public:
|
||||
for (const auto &type : Serialize::Type::GetTypeOrder())
|
||||
{
|
||||
auto *s_type = Serialize::Type::Find(type);
|
||||
if (!s_type || !s_type->GetOwner())
|
||||
continue;
|
||||
|
||||
size_t idx, max;
|
||||
yyjson_mut_val *elem;
|
||||
yyjson_mut_arr_foreach(data, idx, max, elem)
|
||||
{
|
||||
Data ld(elem);
|
||||
s_type->Unserialize(nullptr, ld);
|
||||
}
|
||||
if (s_type && !s_type->GetOwner())
|
||||
LoadType(s_type, data);
|
||||
}
|
||||
|
||||
loaded = false;
|
||||
loaded = true;
|
||||
return EVENT_STOP;
|
||||
}
|
||||
|
||||
@@ -413,15 +421,8 @@ public:
|
||||
it = databases.emplace(s_type->GetOwner(), db).first;
|
||||
}
|
||||
|
||||
auto &[doc, data] = it->second;
|
||||
|
||||
size_t idx, max;
|
||||
yyjson_mut_val *elem;
|
||||
yyjson_mut_arr_foreach(data, idx, max, elem)
|
||||
{
|
||||
Data ld(elem);
|
||||
s_type->Unserialize(nullptr, ld);
|
||||
}
|
||||
auto &[_, data] = it->second;
|
||||
LoadType(s_type, data);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user