MCPcopy Index your code
hub / github.com/apache/pouchdb / processDocs

Function processDocs

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

Source from the content-addressed store, hash-verified

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