summaryrefslogtreecommitdiff
path: root/controller/PostgreSQL.cpp
diff options
context:
space:
mode:
authorGrant Limberg <[email protected]>2021-06-02 14:08:09 -0700
committerGrant Limberg <[email protected]>2021-06-02 14:08:09 -0700
commitfaf0c6bbfa4ee9baaa285cebd35b27c89b3a2572 (patch)
treed1487544b38788102455b45885caa83bc623af53 /controller/PostgreSQL.cpp
parent79f1e8174572dc89258645dc324f22109137a34d (diff)
make sure to commit on online notification thread
Diffstat (limited to 'controller/PostgreSQL.cpp')
-rw-r--r--controller/PostgreSQL.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/controller/PostgreSQL.cpp b/controller/PostgreSQL.cpp
index 1fa05762..c15c8581 100644
--- a/controller/PostgreSQL.cpp
+++ b/controller/PostgreSQL.cpp
@@ -1224,7 +1224,9 @@ void PostgreSQL::onlineNotification_Postgres()
memberUpdate << "INSERT INTO ztc_member_status (network_id, member_id, address, last_updated) VALUES ";
bool firstRun = true;
bool memberAdded = false;
+ int updateCount = 0;
for (auto i=lastOnline.begin(); i != lastOnline.end(); ++i) {
+ updateCount += 1;
uint64_t nwid_i = i->first.first;
char nwidTmp[64];
char memTmp[64];
@@ -1275,8 +1277,12 @@ void PostgreSQL::onlineNotification_Postgres()
memberUpdate << " ON CONFLICT (network_id, member_id) DO UPDATE SET address = EXCLUDED.address, last_updated = EXCLUDED.last_updated;";
if (memberAdded) {
+ fprintf(stderr, "%s\n", memberUpdate.str().c_str());
pqxx::result res = w.exec0(memberUpdate.str());
+ w.commit();
}
+ fprintf(stderr, "Updated online status of %d members\n", updateCount);
+ _pool->unborrow(c);
} catch (std::exception &e) {
fprintf(stderr, "%s: error in onlinenotification thread: %s\n", _myAddressStr.c_str(), e.what());
}