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

Function updateViewInQueue

lib/index.js:8608–8789  ·  view source on GitHub ↗
(view, opts)

Source from the content-addressed store, hash-verified

8606 }
8607
8608 async function updateViewInQueue(view, opts) {
8609 // bind the emit function once
8610 let mapResults;
8611 let doc;
8612 let taskId;
8613
8614 function emit(key, value) {
8615 const output = {id: doc._id, key: normalizeKey(key)};
8616 // Don't explicitly store the value unless it's defined and non-null.
8617 // This saves on storage space, because often people don't use it.
8618 if (typeof value !== 'undefined' && value !== null) {
8619 output.value = normalizeKey(value);
8620 }
8621 mapResults.push(output);
8622 }
8623
8624 const mapFun = mapper(view.mapFun, emit);
8625
8626 let currentSeq = view.seq || 0;
8627
8628 function createTask() {
8629 return view.sourceDB.info().then(function (info) {
8630 taskId = view.sourceDB.activeTasks.add({
8631 name: 'view_indexing',
8632 total_items: info.update_seq - currentSeq,
8633 });
8634 });
8635 }
8636
8637 function processChange(docIdsToChangesAndEmits, seq) {
8638 return function () {
8639 return saveKeyValues(view, docIdsToChangesAndEmits, seq);
8640 };
8641 }
8642
8643 let indexed_docs = 0;
8644 const progress = {
8645 view: view.name,
8646 indexed_docs
8647 };
8648 view.sourceDB.emit('indexing', progress);
8649
8650 const queue = new TaskQueue$1();
8651
8652 async function processNextBatch() {
8653 const response = await view.sourceDB.changes({
8654 return_docs: true,
8655 conflicts: true,
8656 include_docs: true,
8657 style: 'all_docs',
8658 since: currentSeq,
8659 limit: opts.changes_batch_size
8660 });
8661 const purges = await getRecentPurges();
8662 return processBatch(response, purges);
8663 }
8664
8665 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…