Skip to content

Commit 8207da7

Browse files
nolanlawsondaleharvey
authored andcommitted
(#3908) - prefer non-inlined attachments for allDocs()
1 parent 6bd6540 commit 8207da7

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

lib/replicate/get-docs.js

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,32 +59,23 @@ function getDocs(src, diffs, state) {
5959
return Promise.all(diffKeys.map(processDiffDoc));
6060
}
6161

62-
function hasValidAttachments(doc) {
63-
var atts = doc._attachments;
64-
var attNames = atts && Object.keys(atts);
65-
66-
var hasAttachments = atts && attNames.length > 0;
67-
// These will be stubs in CouchDB < 1.6 because attachments
68-
// weren't supported in _all_docs
69-
var hasAttachmentData = hasAttachments && !atts[attNames[0]].stub;
70-
71-
return !hasAttachments || hasAttachmentData;
62+
function hasAttachments(doc) {
63+
return doc._attachments && Object.keys(doc._attachments).length > 0;
7264
}
7365

7466
function fetchRevisionOneDocs(ids) {
7567
// Optimization: fetch gen-1 docs and attachments in
7668
// a single request using _all_docs
7769
return src.allDocs({
7870
keys: ids,
79-
include_docs: true,
80-
attachments: true
71+
include_docs: true
8172
}).then(function (res) {
8273
if (state.cancelled) {
8374
throw new Error('cancelled');
8475
}
8576
res.rows.forEach(function (row) {
8677
if (row.deleted || !row.doc || !isGenOne(row.value.rev) ||
87-
!hasValidAttachments(row.doc)) {
78+
hasAttachments(row.doc)) {
8879
// if any of these conditions apply, we need to fetch using get()
8980
return;
9081
}

0 commit comments

Comments
 (0)