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

Function saveKeyValues

lib/index-browser.js:8534–8553  ·  view source on GitHub ↗
(view, docIdsToChangesAndEmits, seq)

Source from the content-addressed store, hash-verified

8532 // updates all emitted key/value docs and metaDocs in the mrview database
8533 // for the given batch of documents from the source database
8534 function saveKeyValues(view, docIdsToChangesAndEmits, seq) {
8535 var seqDocId = '_local/lastSeq';
8536 return view.db.get(seqDocId)
8537 .catch(defaultsTo({_id: seqDocId, seq: 0}))
8538 .then(function (lastSeqDoc) {
8539 var docIds = mapToKeysArray(docIdsToChangesAndEmits);
8540 return Promise.all(docIds.map(function (docId) {
8541 return getDocsToPersist(docId, view, docIdsToChangesAndEmits);
8542 })).then(function (listOfDocsToPersist) {
8543 var docsToPersist = listOfDocsToPersist.flat();
8544 lastSeqDoc.seq = seq;
8545 docsToPersist.push(lastSeqDoc);
8546 // write all docs in a single operation, update the seq once
8547 return view.db.bulkDocs({docs : docsToPersist});
8548 })
8549 // TODO: this should be placed somewhere else, probably? we're querying both docs twice
8550 // (first time when getting the actual purges).
8551 .then(() => updatePurgeSeq(view));
8552 });
8553 }
8554
8555 function getQueue(view) {
8556 const viewName = typeof view === 'string' ? view : view.name;

Callers 1

processChangeFunction · 0.70

Calls 5

defaultsToFunction · 0.70
mapToKeysArrayFunction · 0.70
getDocsToPersistFunction · 0.70
updatePurgeSeqFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…