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

Function updateViewInQueue

lib/index-browser.js:8570–8751  ·  view source on GitHub ↗
(view, opts)

Source from the content-addressed store, hash-verified

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