summaryrefslogtreecommitdiff
path: root/controller/PostgreSQL.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'controller/PostgreSQL.cpp')
-rw-r--r--controller/PostgreSQL.cpp28
1 files changed, 26 insertions, 2 deletions
diff --git a/controller/PostgreSQL.cpp b/controller/PostgreSQL.cpp
index 45be3e51..121d00df 100644
--- a/controller/PostgreSQL.cpp
+++ b/controller/PostgreSQL.cpp
@@ -165,12 +165,35 @@ bool PostgreSQL::isReady()
return ((_ready == 2)&&(_connected));
}
-void PostgreSQL::save(nlohmann::json *orig, nlohmann::json &record)
+void PostgreSQL::save(nlohmann::json &record)
{
try {
- if (!record.is_object()) {
+ if (!record.is_object())
return;
+ const std::string objtype = record["objtype"];
+ if (objtype == "network") {
+ const uint64_t nwid = OSUtils::jsonIntHex(record["id"],0ULL);
+ if (nwid) {
+ nlohmann::json old;
+ get(nwid,old);
+ if ((!old.is_object())||(old != record)) {
+ record["revision"] = OSUtils::jsonInt(record["revision"],0ULL) + 1ULL;
+ _commitQueue.post(new nlohmann::json(record));
+ }
+ }
+ } else if (objtype == "member") {
+ const uint64_t nwid = OSUtils::jsonIntHex(record["nwid"],0ULL);
+ const uint64_t id = OSUtils::jsonIntHex(record["id"],0ULL);
+ if ((id)&&(nwid)) {
+ nlohmann::json network,old;
+ get(nwid,network,id,old);
+ if ((!old.is_object())||(old != record)) {
+ record["revision"] = OSUtils::jsonInt(record["revision"],0ULL) + 1ULL;
+ _commitQueue.post(new nlohmann::json(record));
+ }
+ }
}
+ /*
waitForReady();
if (orig) {
if (*orig != record) {
@@ -181,6 +204,7 @@ void PostgreSQL::save(nlohmann::json *orig, nlohmann::json &record)
record["revision"] = 1;
_commitQueue.post(new nlohmann::json(record));
}
+ */
} catch (std::exception &e) {
fprintf(stderr, "Error on PostgreSQL::save: %s\n", e.what());
} catch (...) {