Commit 46d16a94907516fbe8124c691d904a5b57916575
Factor out merging results
Merge flags alsocel committed on 11/26/2016, 6:16:45 PM
Parent: 7216c5147c617ec965b6bf02ee91da180a9d4cb7
Files changed
lib/query.js | changed |
lib/query.js | ||
---|---|---|
@@ -9,9 +9,9 @@ | ||
9 | 9 … | && a.type === b.type |
10 | 10 … | && a.class === b.class); |
11 | 11 … | } |
12 | 12 … | |
13 | -function merge(into, from) { | |
13 … | +function mergeRecords(into, from) { | |
14 | 14 … | if (from) from.filter(function (a) { |
15 | 15 … | return into.every(function (b) { |
16 | 16 … | return !isRecordEqual(a, b); |
17 | 17 … | }) |
@@ -19,8 +19,18 @@ | ||
19 | 19 … | into.push(rec); |
20 | 20 … | }); |
21 | 21 … | } |
22 | 22 … | |
23 … | +function mergeResults(into, from) { | |
24 … | + mergeRecords(into.additionals, from.additionals); | |
25 … | + mergeRecords(into.answers, from.answers); | |
26 … | + mergeRecords(into.authorities, from.authorities); | |
27 … | + mergeRecords(into.questions, from.questions); | |
28 … | + if (from.expires < into.expires) into.expires = from.expires; | |
29 … | + into.domainExists |= from.domainExists | |
30 … | + into.authoritative |= from.authoritative | |
31 … | +} | |
32 … | + | |
23 | 33 … | Query.branches = function (sbot, name, type, _class, cb) { |
24 | 34 … | if (!_class) _class = "IN"; |
25 | 35 … | var branches = []; |
26 | 36 … | Pull(Query.all(sbot), |
@@ -214,13 +224,9 @@ | ||
214 | 224 … | |
215 | 225 … | function next(err, res) { |
216 | 226 … | if (err) return waiting = 0, cb(err); |
217 | 227 … | |
218 | - merge(result.additionals, res.additionals); | |
219 | - merge(result.answers, res.answers); | |
220 | - merge(result.authorities, res.authorities); | |
221 | - merge(result.questions, res.questions); | |
222 | - if (res.expires < result.expires) result.expires = res.expires; | |
228 … | + mergeResults(result, res) | |
223 | 229 … | |
224 | 230 … | // recurse on CNAMEs |
225 | 231 … | if (!isTransfer && question.type !== 'CNAME') { |
226 | 232 … | var stack2 = stack.concat(question) |
Built with git-ssb-web