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

Function processBatch

lib/index.es.js:275–324  ·  view source on GitHub ↗
(batch, offset)

Source from the content-addressed store, hash-verified

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

Callers 2

nextBatchFunction · 0.70
processNextBatchFunction · 0.70

Calls 9

pickFunction · 0.70
gotResultFunction · 0.70
nextBatchFunction · 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…