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

Function processBatch

lib/index.js:280–329  ·  view source on GitHub ↗
(batch, offset)

Source from the content-addressed store, hash-verified

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

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…