From: bert hubert Date: Tue, 8 Dec 2015 08:55:45 +0000 (+0100) Subject: make grepq look at the the n newest queries, not the n oldest queries X-Git-Tag: dnsdist-1.0.0-alpha1~101 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b049c29be790c36908dbe9d26a0720f2b0909ff3;p=pdns make grepq look at the the n newest queries, not the n oldest queries --- diff --git a/pdns/dnsdist-lua2.cc b/pdns/dnsdist-lua2.cc index 90c9daafd..9c036ecb2 100644 --- a/pdns/dnsdist-lua2.cc +++ b/pdns/dnsdist-lua2.cc @@ -218,14 +218,22 @@ void moreLua() ReadLock rl(&g_rings.queryLock); qr=g_rings.queryRing; } + sort(qr.begin(), qr.end(), [](const decltype(qr)::value_type& a, const decltype(qr)::value_type& b) { + return b.when < a.when; + }); { std::lock_guard lock(g_rings.respMutex); rr=g_rings.respRing; } + + sort(rr.begin(), rr.end(), [](const decltype(rr)::value_type& a, const decltype(rr)::value_type& b) { + return b.when < a.when; + }); unsigned int num=0; struct timespec now; clock_gettime(CLOCK_MONOTONIC, &now); + std::multimap out; for(const auto& c : qr) { if((nm && nm->match(c.requestor)) || (dn && c.name.isPartOf(*dn))) {