MCPcopy
hub / github.com/apache/pouchdb / processBatch

Function processBatch

lib/index-browser.js:276–325  ·  view source on GitHub ↗
(batch, offset)

Source from the content-addressed store, hash-verified

274 }
275
276 function processBatch(batch, offset) {
277 batch.forEach(function (docId, j) {
278 var docIdx = offset + j;
279 var docRequests = requestsById.get(docId);
280
281 // just use the first request as the "template"
282 // TODO: The _bulk_get API allows for more subtle use cases than this,
283 // but for now it is unlikely that there will be a mix of different
284 // "atts_since" or "attachments" in the same request, since it's just
285 // replicate.js that is using this for the moment.
286 // Also, atts_since is aspirational, since we don't support it yet.
287 var docOpts = pick(docRequests[0], ['atts_since', 'attachments']);
288 docOpts.open_revs = docRequests.map(function (request) {
289 // rev is optional, open_revs disallowed
290 return request.rev;
291 });
292
293 // remove falsey / undefined revisions
294 docOpts.open_revs = docOpts.open_revs.filter(identityFunction);
295
296 var formatResult = identityFunction;
297
298 if (docOpts.open_revs.length === 0) {
299 delete docOpts.open_revs;
300
301 // when fetching only the "winning" leaf,
302 // transform the result so it looks like an open_revs
303 // request
304 formatResult = formatResultForOpenRevsGet;
305 }
306
307 // globally-supplied options
308 ['revs', 'attachments', 'binary', 'ajax', 'latest'].forEach(function (param) {
309 if (param in opts) {
310 docOpts[param] = opts[param];
311 }
312 });
313 db.get(docId, docOpts, function (err, res) {
314 var result;
315 /* istanbul ignore if */
316 if (err) {
317 result = [{error: err}];
318 } else {
319 result = formatResult(res);
320 }
321 gotResult(docIdx, docId, result);
322 nextBatch();
323 });
324 });
325 }
326
327 nextBatch();
328

Callers 4

nextBatchFunction · 0.70
onBatchFunction · 0.70
onGetAllFunction · 0.70
processNextBatchFunction · 0.70

Calls 11

pickFunction · 0.70
gotResultFunction · 0.70
nextBatchFunction · 0.70
decodeMetadataFunction · 0.70
allDocsInnerFunction · 0.70
processChangeFunction · 0.70
processNextBatchFunction · 0.70
getMethod · 0.45
addMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…