]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Optimization for the ADDR case: stop loop if we found 2 (A and AAAA)
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Wed, 21 Aug 2024 09:55:35 +0000 (11:55 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Wed, 2 Oct 2024 08:33:55 +0000 (10:33 +0200)
pdns/recursordist/recursor_cache.cc

index b487ffc3370703c8a9ee8132c8dbe6441ceeab02..7071b800acd0ecd4d536e2459c885a4cdaf69d77 100644 (file)
@@ -419,7 +419,7 @@ time_t MemRecursorCache::get(time_t now, const DNSName& qname, const QType qtype
 
   if (routingTag) {
     auto entries = getEntries(*lockedShard, qname, qtype, routingTag);
-    bool found = false;
+    unsigned int found = 0;
     time_t ttd{};
 
     if (entries.first != entries.second) {
@@ -436,17 +436,20 @@ time_t MemRecursorCache::get(time_t now, const DNSName& qname, const QType qtype
         if (!entryMatches(firstIndexIterator, qtype, requireAuth, who)) {
           continue;
         }
-        found = true;
+        ++found;
 
         handleServeStaleBookkeeping(now, serveStale, firstIndexIterator);
 
         ttd = handleHit(now, *lockedShard, firstIndexIterator, qname, origTTL, res, signatures, authorityRecs, variable, cachedState, wasAuth, fromAuthZone, fromAuthIP);
 
-        if (qtype != QType::ANY && qtype != QType::ADDR) { // normally if we have a hit, we are done
+        if (qtype == QType::ADDR && found == 2) {
+          break;
+        }
+        if (qtype != QType::ANY) { // normally if we have a hit, we are done
           break;
         }
       }
-      if (found) {
+      if (found > 0) {
         if (cachedState && ttd > now) {
           ptrAssign(state, *cachedState);
         }
@@ -460,7 +463,7 @@ time_t MemRecursorCache::get(time_t now, const DNSName& qname, const QType qtype
 
   if (entries.first != entries.second) {
     OrderedTagIterator_t firstIndexIterator;
-    bool found = false;
+    unsigned int found = 0;
     time_t ttd{};
 
     for (auto i = entries.first; i != entries.second; ++i) {
@@ -475,17 +478,20 @@ time_t MemRecursorCache::get(time_t now, const DNSName& qname, const QType qtype
       if (!entryMatches(firstIndexIterator, qtype, requireAuth, who)) {
         continue;
       }
-      found = true;
+      ++found;
 
       handleServeStaleBookkeeping(now, serveStale, firstIndexIterator);
 
       ttd = handleHit(now, *lockedShard, firstIndexIterator, qname, origTTL, res, signatures, authorityRecs, variable, cachedState, wasAuth, fromAuthZone, fromAuthIP);
 
-      if (qtype != QType::ANY && qtype != QType::ADDR) { // normally if we have a hit, we are done
+      if (qtype == QType::ADDR && found == 2) {
+        break;
+      }
+      if (qtype != QType::ANY) { // normally if we have a hit, we are done
         break;
       }
     }
-    if (found) {
+    if (found > 0) {
       if (cachedState && ttd > now) {
         ptrAssign(state, *cachedState);
       }
@@ -636,6 +642,7 @@ void MemRecursorCache::replace(time_t now, const DNSName& qname, const QType qty
       break;
     }
   }
+
   if (!isNew) {
     moveCacheItemToBack<SequencedTag>(lockedShard->d_map, stored);
   }