summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorSadie Powell <sadie@witchery.services>2025-05-11 16:38:32 +0100
committerSadie Powell <sadie@witchery.services>2025-05-11 16:45:44 +0100
commit19f83eaa34e95a25373437728c8ab3316a3f273c (patch)
treeeabc48af13f37629b3683eeada7c30a1359be554 /modules
parentb1212f9e899973497f8f12fa30805a5c2e44e5eb (diff)
Fix loading databases in db_json.
Diffstat (limited to 'modules')
-rw-r--r--modules/database/db_json.cpp41
1 files changed, 21 insertions, 20 deletions
diff --git a/modules/database/db_json.cpp b/modules/database/db_json.cpp
index 9796ea7f3..a43acc36b 100644
--- a/modules/database/db_json.cpp
+++ b/modules/database/db_json.cpp
@@ -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);
}
};