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

Function saveKeyValues

lib/index.es.js:8567–8586  ·  view source on GitHub ↗
(view, docIdsToChangesAndEmits, seq)

Source from the content-addressed store, hash-verified

8565 // updates all emitted key/value docs and metaDocs in the mrview database
8566 // for the given batch of documents from the source database
8567 function saveKeyValues(view, docIdsToChangesAndEmits, seq) {
8568 var seqDocId = '_local/lastSeq';
8569 return view.db.get(seqDocId)
8570 .catch(defaultsTo({_id: seqDocId, seq: 0}))
8571 .then(function (lastSeqDoc) {
8572 var docIds = mapToKeysArray(docIdsToChangesAndEmits);
8573 return Promise.all(docIds.map(function (docId) {
8574 return getDocsToPersist(docId, view, docIdsToChangesAndEmits);
8575 })).then(function (listOfDocsToPersist) {
8576 var docsToPersist = listOfDocsToPersist.flat();
8577 lastSeqDoc.seq = seq;
8578 docsToPersist.push(lastSeqDoc);
8579 // write all docs in a single operation, update the seq once
8580 return view.db.bulkDocs({docs : docsToPersist});
8581 })
8582 // TODO: this should be placed somewhere else, probably? we're querying both docs twice
8583 // (first time when getting the actual purges).
8584 .then(() => updatePurgeSeq(view));
8585 });
8586 }
8587
8588 function getQueue(view) {
8589 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…