make sure to commit on online notification thread

This commit is contained in:
Grant Limberg 2021-06-02 14:08:09 -07:00
parent 79f1e81745
commit faf0c6bbfa
No known key found for this signature in database
GPG Key ID: 2BA62CCABBB4095A

View File

@ -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());
}