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

Function processDocs

lib/index.es.js:4718–4810  ·  view source on GitHub ↗
(revLimit, docInfos, api, fetchedDocs, tx, results,
                     writeDoc, opts, overallCallback)

Source from the content-addressed store, hash-verified

4716}
4717
4718function processDocs(revLimit, docInfos, api, fetchedDocs, tx, results,
4719 writeDoc, opts, overallCallback) {
4720
4721 // Default to 1000 locally
4722 revLimit = revLimit || 1000;
4723
4724 function insertDoc(docInfo, resultsIdx, callback) {
4725 // Cant insert new deleted documents
4726 var winningRev$$1 = winningRev(docInfo.metadata);
4727 var deleted = isDeleted(docInfo.metadata, winningRev$$1);
4728 if ('was_delete' in opts && deleted) {
4729 results[resultsIdx] = createError(MISSING_DOC, 'deleted');
4730 return callback();
4731 }
4732
4733 // 4712 - detect whether a new document was inserted with a _rev
4734 var inConflict = newEdits && rootIsMissing(docInfo);
4735
4736 if (inConflict) {
4737 var err = createError(REV_CONFLICT);
4738 results[resultsIdx] = err;
4739 return callback();
4740 }
4741
4742 var delta = deleted ? 0 : 1;
4743
4744 writeDoc(docInfo, winningRev$$1, deleted, deleted, false,
4745 delta, resultsIdx, callback);
4746 }
4747
4748 var newEdits = opts.new_edits;
4749 var idsToDocs = new Map();
4750
4751 var docsDone = 0;
4752 var docsToDo = docInfos.length;
4753
4754 function checkAllDocsDone() {
4755 if (++docsDone === docsToDo && overallCallback) {
4756 overallCallback();
4757 }
4758 }
4759
4760 docInfos.forEach(function (currentDoc, resultsIdx) {
4761
4762 if (currentDoc._id && isLocalId(currentDoc._id)) {
4763 var fun = currentDoc._deleted ? '_removeLocal' : '_putLocal';
4764 api[fun](currentDoc, {ctx: tx}, function (err, res) {
4765 results[resultsIdx] = err || res;
4766 checkAllDocsDone();
4767 });
4768 return;
4769 }
4770
4771 var id = currentDoc.metadata.id;
4772 if (idsToDocs.has(id)) {
4773 docsToDo--; // duplicate
4774 idsToDocs.get(id).push([currentDoc, resultsIdx]);
4775 } else {

Callers 1

LevelPouchFunction · 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…