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

Function processDocs

lib/index-browser.js:4578–4670  ·  view source on GitHub ↗
(revLimit, docInfos, api, fetchedDocs, tx, results,
                     writeDoc, opts, overallCallback)

Source from the content-addressed store, hash-verified

4576}
4577
4578function processDocs(revLimit, docInfos, api, fetchedDocs, tx, results,
4579 writeDoc, opts, overallCallback) {
4580
4581 // Default to 1000 locally
4582 revLimit = revLimit || 1000;
4583
4584 function insertDoc(docInfo, resultsIdx, callback) {
4585 // Cant insert new deleted documents
4586 var winningRev$$1 = winningRev(docInfo.metadata);
4587 var deleted = isDeleted(docInfo.metadata, winningRev$$1);
4588 if ('was_delete' in opts && deleted) {
4589 results[resultsIdx] = createError(MISSING_DOC, 'deleted');
4590 return callback();
4591 }
4592
4593 // 4712 - detect whether a new document was inserted with a _rev
4594 var inConflict = newEdits && rootIsMissing(docInfo);
4595
4596 if (inConflict) {
4597 var err = createError(REV_CONFLICT);
4598 results[resultsIdx] = err;
4599 return callback();
4600 }
4601
4602 var delta = deleted ? 0 : 1;
4603
4604 writeDoc(docInfo, winningRev$$1, deleted, deleted, false,
4605 delta, resultsIdx, callback);
4606 }
4607
4608 var newEdits = opts.new_edits;
4609 var idsToDocs = new Map();
4610
4611 var docsDone = 0;
4612 var docsToDo = docInfos.length;
4613
4614 function checkAllDocsDone() {
4615 if (++docsDone === docsToDo && overallCallback) {
4616 overallCallback();
4617 }
4618 }
4619
4620 docInfos.forEach(function (currentDoc, resultsIdx) {
4621
4622 if (currentDoc._id && isLocalId(currentDoc._id)) {
4623 var fun = currentDoc._deleted ? '_removeLocal' : '_putLocal';
4624 api[fun](currentDoc, {ctx: tx}, function (err, res) {
4625 results[resultsIdx] = err || res;
4626 checkAllDocsDone();
4627 });
4628 return;
4629 }
4630
4631 var id = currentDoc.metadata.id;
4632 if (idsToDocs.has(id)) {
4633 docsToDo--; // duplicate
4634 idsToDocs.get(id).push([currentDoc, resultsIdx]);
4635 } else {

Callers 1

idbProcessDocsFunction · 0.70

Calls 4

isLocalIdFunction · 0.70
checkAllDocsDoneFunction · 0.70
nextDocFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…