From c6b7c263d26ba3eb320470f745888a29323f99d6 Mon Sep 17 00:00:00 2001 From: Grant Limberg Date: Thu, 25 Sep 2025 16:09:57 -0700 Subject: [PATCH] query fix for new networks --- nonfree/controller/CentralDB.cpp | 16 ++++++++++++---- nonfree/controller/PubSubListener.cpp | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/nonfree/controller/CentralDB.cpp b/nonfree/controller/CentralDB.cpp index a05d9bb37..b39ac6dd1 100644 --- a/nonfree/controller/CentralDB.cpp +++ b/nonfree/controller/CentralDB.cpp @@ -1303,21 +1303,29 @@ void CentralDB::commitThread() std::string id = config["id"]; pqxx::row nwrow = - w.exec( - "SELECT COUNT(id), frontend FROM networks_ctl WHERE id = $1 GROUP BY frontend", - pqxx::params { id }) + w.exec("SELECT COUNT(id) frontend FROM networks_ctl WHERE id = $1", pqxx::params { id }) .one_row(); int nwcount = nwrow[0].as(); - std::string frontend = nwrow[1].as(); bool isNewNetwork = (nwcount == 0); + std::string frontend = ""; + + if (! isNewNetwork) { + pqxx::row nwrow = + w.exec("SELECT frontend FROM networks_ctl WHERE id = $1", pqxx::params { id }).one_row(); + frontend = nwrow[0].as(); + } std::string change_source; if (! config["change_source"].is_null()) { change_source = config["change_source"]; } + if (! isNewNetwork && change_source != "controller" && frontend != change_source) { // if it is not a new network and the change source is not the controller and doesn't match the // frontend, don't apply the change. + fprintf( + stderr, "Skipping network update %s. isNewNetwork: %s, change_source: %s, frontend: %s\n", + id.c_str(), isNewNetwork ? "true" : "false", change_source.c_str(), frontend.c_str()); continue; } diff --git a/nonfree/controller/PubSubListener.cpp b/nonfree/controller/PubSubListener.cpp index 250bf00c9..623b3ba97 100644 --- a/nonfree/controller/PubSubListener.cpp +++ b/nonfree/controller/PubSubListener.cpp @@ -134,7 +134,7 @@ void PubSubNetworkListener::onNotification(const std::string& payload) return; } - fprintf(stderr, "Network notification received"); + fprintf(stderr, "Network notification received\n"); try { nlohmann::json oldConfig, newConfig;