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