MCPcopy Create free account
hub / github.com/apache/pouchdb / updateViewInQueue

Function updateViewInQueue

lib/index-browser.es.js:8566–8747  ·  view source on GitHub ↗
(view, opts)

Source from the content-addressed store, hash-verified

8564 }
8565
8566 async function updateViewInQueue(view, opts) {
8567 // bind the emit function once
8568 let mapResults;
8569 let doc;
8570 let taskId;
8571
8572 function emit(key, value) {
8573 const output = {id: doc._id, key: normalizeKey(key)};
8574 // Don't explicitly store the value unless it's defined and non-null.
8575 // This saves on storage space, because often people don't use it.
8576 if (typeof value !== 'undefined' && value !== null) {
8577 output.value = normalizeKey(value);
8578 }
8579 mapResults.push(output);
8580 }
8581
8582 const mapFun = mapper(view.mapFun, emit);
8583
8584 let currentSeq = view.seq || 0;
8585
8586 function createTask() {
8587 return view.sourceDB.info().then(function (info) {
8588 taskId = view.sourceDB.activeTasks.add({
8589 name: 'view_indexing',
8590 total_items: info.update_seq - currentSeq,
8591 });
8592 });
8593 }
8594
8595 function processChange(docIdsToChangesAndEmits, seq) {
8596 return function () {
8597 return saveKeyValues(view, docIdsToChangesAndEmits, seq);
8598 };
8599 }
8600
8601 let indexed_docs = 0;
8602 const progress = {
8603 view: view.name,
8604 indexed_docs
8605 };
8606 view.sourceDB.emit('indexing', progress);
8607
8608 const queue = new TaskQueue$1();
8609
8610 async function processNextBatch() {
8611 const response = await view.sourceDB.changes({
8612 return_docs: true,
8613 conflicts: true,
8614 include_docs: true,
8615 style: 'all_docs',
8616 since: currentSeq,
8617 limit: opts.changes_batch_size
8618 });
8619 const purges = await getRecentPurges();
8620 return processBatch(response, purges);
8621 }
8622
8623 function getRecentPurges() {

Callers 1

updateViewFunction · 0.70

Calls 5

finishMethod · 0.95
mapperFunction · 0.70
createTaskFunction · 0.70
processNextBatchFunction · 0.70
removeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…