From 393eb13e81d2f0f88acb4b83e132124c3d376401 Mon Sep 17 00:00:00 2001 From: onefang Date: Sun, 29 Dec 2019 10:16:06 +1000 Subject: Refactor nested pairs() calls. --- apt-panopticon-report-email-web.lua | 82 ++++++++++--------------------------- 1 file changed, 22 insertions(+), 60 deletions(-) (limited to 'apt-panopticon-report-email-web.lua') diff --git a/apt-panopticon-report-email-web.lua b/apt-panopticon-report-email-web.lua index 7d5ce7f..5598515 100755 --- a/apt-panopticon-report-email-web.lua +++ b/apt-panopticon-report-email-web.lua @@ -205,33 +205,20 @@ if nil == email then C("opening mirrors file - " .. e) else -- DNS-RR test. if ("deb.devuan.org" ~= k) and (nil ~= APT.mirrors["deb.devuan.org"]) then - for l, w in pairs(APT.mirrors[k].IPs) do - if type(w) == "table" then - for i, u in pairs(w) do - if nil ~= APT.mirrors["deb.devuan.org"].IPs["deb.roundr.devuan.org"][i] then - local log = logCount("deb.devuan.org", i) - if "" ~= log then - if "" == dns then dns = " " else dns = dns .. " " end - dns = dns .. logCount("deb.devuan.org", i) - else - if "" == dns then dns = " " else dns = dns .. " " end - dns = dns .. i - end - end - end - else - if nil ~= APT.mirrors["deb.devuan.org"].IPs["deb.roundr.devuan.org"][l] then - local log = logCount("deb.devuan.org", l) + APT.allpairs(APT.mirrors[k].IPs, + function(i, w, k, v) + if nil ~= APT.mirrors["deb.devuan.org"].IPs["deb.roundr.devuan.org"][i] then + local log = logCount("deb.devuan.org", i) if "" ~= log then if "" == dns then dns = " " else dns = dns .. " " end - dns = dns .. log + dns = dns .. logCount("deb.devuan.org", i) else if "" == dns then dns = " " else dns = dns .. " " end - dns = dns .. l + dns = dns .. i end end end - end + ) if "" == dns then dns = "[no]" end dns = " DNS-RR: " .. dns end @@ -396,33 +383,20 @@ if nil == web then C("opening mirrors file - " .. e) else -- DNS-RR test. if ("deb.devuan.org" ~= k) and (nil ~= APT.mirrors["deb.devuan.org"]) then - for l, w in pairs(APT.mirrors[k].IPs) do - if type(w) == "table" then - for i, u in pairs(w) do - if nil ~= APT.mirrors["deb.devuan.org"].IPs["deb.roundr.devuan.org"][i] then - local log = logCount("deb.devuan.org", i) - if "" ~= log then - if "" == dns then dns = " " else dns = dns .. "   " end - dns = dns .. logCount("deb.devuan.org", i) - else - if "" == dns then dns = " " else dns = dns .. "   " end - dns = dns .. "" .. i .. "" - end - end - end - else - if nil ~= APT.mirrors["deb.devuan.org"].IPs["deb.roundr.devuan.org"][l] then - local log = logCount("deb.devuan.org", l) + APT.allpairs(APT.mirrors[k].IPs, + function(i, w, k, v) + if nil ~= APT.mirrors["deb.devuan.org"].IPs["deb.roundr.devuan.org"][i] then + local log = logCount("deb.devuan.org", i) if "" ~= log then if "" == dns then dns = " " else dns = dns .. "   " end - dns = dns .. log + dns = dns .. logCount("deb.devuan.org", i) else if "" == dns then dns = " " else dns = dns .. "   " end - dns = dns .. "" .. l .. "" + dns = dns .. "" .. i .. "" end end end - end + ) if "" == dns then dns = "no" end if 0 == max then @@ -495,6 +469,7 @@ if nil == web then C("opening mirrors file - " .. e) else APT.mirrors[k].BaseURL = nil APT.mirrors[k].Country = nil APT.mirrors[k].Bandwidth = nil + for l, w in pairs(APT.mirrors[k].IPs) do if type(w) == "table" then n[l] = {} @@ -564,33 +539,20 @@ if nil == web then C("opening mirrors file - " .. e) else -- DNS-RR test. if ("deb.devuan.org" ~= k) and (nil ~= APT.debians["deb.devuan.org"]) then - for l, w in pairs(APT.debians[k].IPs) do - if type(w) == "table" then - for i, u in pairs(w) do - if nil ~= APT.debians["deb.devuan.org"].IPs["deb.roundr.devuan.org"][i] then - local log = logCount("deb.devuan.org", i) - if "" ~= log then - if "" == dns then dns = " " else dns = dns .. "   " end - dns = dns .. logCount("deb.devuan.org", i) - else - if "" == dns then dns = " " else dns = dns .. "   " end - dns = dns .. "" .. i .. "" - end - end - end - else - if nil ~= APT.debians["deb.devuan.org"].IPs["deb.roundr.devuan.org"][l] then - local log = logCount("deb.devuan.org", l) + APT.allpairs(APT.debians[k].IPs, + function(i, w, k, v) + if nil ~= APT.mirrors["deb.devuan.org"].IPs["deb.roundr.devuan.org"][i] then + local log = logCount("deb.devuan.org", i) if "" ~= log then if "" == dns then dns = " " else dns = dns .. "   " end - dns = dns .. log + dns = dns .. logCount("deb.devuan.org", i) else if "" == dns then dns = " " else dns = dns .. "   " end - dns = dns .. "" .. l .. "" + dns = dns .. "" .. i .. "" end end end - end + ) if "" == dns then dns = "no" end if 0 == max then -- cgit v1.1