summaryrefslogtreecommitdiff
path: root/controller/PostgreSQL.cpp
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2019-08-06 08:51:23 -0500
committerAdam Ierymenko <adam.ierymenko@gmail.com>2019-08-06 08:51:23 -0500
commit3c776675b3824d4497d913386793efaece2ee7d1 (patch)
tree92d0cccb701a041cb9aa730d1baf028568137835 /controller/PostgreSQL.cpp
parent37d508ab969afaf16c2aee1838a225022de34177 (diff)
downloadinfinitytier-3c776675b3824d4497d913386793efaece2ee7d1.tar.gz
infinitytier-3c776675b3824d4497d913386793efaece2ee7d1.zip
Cruftectomy, work in progress on mirrorring
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 (...) {