]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Refactor doGenericTopRemotes()
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Mon, 4 Nov 2024 08:47:36 +0000 (09:47 +0100)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Mon, 4 Nov 2024 08:47:36 +0000 (09:47 +0100)
pdns/recursordist/rec_channel_rec.cc

index 9fc6230740405848370c90b2f7d6d454b2c0c78b..21e9e0a676cdd7b025c72d071ae97404e8aa4a51 100644 (file)
@@ -1516,20 +1516,20 @@ vector<ComboAddress>* pleaseGetTimeouts()
 static string doGenericTopRemotes(const pleaseremotefunc_t& func)
 {
   std::map<ComboAddress, int, ComboAddress::addressOnlyLessThan> counts;
-
   auto remotes = broadcastAccFunction<vector<ComboAddress>>(func);
-
-  unsigned int total = 0;
+  if (remotes.empty()) {
+    return "No data available\n";
+  }
+  const unsigned int total = remotes.size();
   for (const auto& address : remotes) {
-    total++;
     counts[address]++;
   }
 
   std::multimap<int, ComboAddress> rcounts;
-
   for (auto& count : counts) {
     rcounts.emplace(-count.second, count.first);
   }
+
   ostringstream ret;
   ret << "Over last " << total << " entries:\n";
   boost::format fmt("%.02f%%\t%s\n");