Skip to content

Commit

Permalink
Merge e993035 into fe7ffa9
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoglan committed Jul 13, 2021
2 parents fe7ffa9 + e993035 commit 12ba6dd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
1 change: 1 addition & 0 deletions docs/_includes/api/create_database.html
Expand Up @@ -16,6 +16,7 @@
* `adapter`: One of `'indexeddb'`, `'idb'`, `'leveldb'`, or `'http'`.
* `revs_limit`: Specify how many old revisions we keep track (not a copy) of. Specifying a low value means Pouch may not be able to figure out whether a new revision received via replication is related to any it currently has which could result in a conflict. Defaults to `1000`.
* `deterministic_revs`: Use a md5 hash to create a deterministic revision number for documents. Setting it to false will mean that the revision number will be a random UUID. Defaults to true.
* `view_update_changes_batch_size`: Specify how many change records will be consumed at a time when rebuilding view indexes when the `query()` method is used. Defaults to 50.

**Options for remote databases:**

Expand Down
20 changes: 12 additions & 8 deletions packages/node_modules/pouchdb-abstract-mapreduce/src/index.js
Expand Up @@ -481,13 +481,13 @@ function createAbstractMapReduce(localDocName, mapper, reducer, ddocValidator) {
return queue;
}

function updateView(view) {
function updateView(view, opts) {
return sequentialize(getQueue(view), function () {
return updateViewInQueue(view);
return updateViewInQueue(view, opts);
})();
}

function updateViewInQueue(view) {
function updateViewInQueue(view, opts) {
// bind the emit function once
var mapResults;
var doc;
Expand Down Expand Up @@ -521,7 +521,7 @@ function createAbstractMapReduce(localDocName, mapper, reducer, ddocValidator) {
include_docs: true,
style: 'all_docs',
since: currentSeq,
limit: CHANGES_BATCH_SIZE
limit: opts.changes_batch_size
}).then(processBatch);
}

Expand All @@ -532,7 +532,7 @@ function createAbstractMapReduce(localDocName, mapper, reducer, ddocValidator) {
}
var docIdsToChangesAndEmits = createDocIdsToChangesAndEmits(results);
queue.add(processChange(docIdsToChangesAndEmits, currentSeq));
if (results.length < CHANGES_BATCH_SIZE) {
if (results.length < opts.changes_batch_size) {
return;
}
return processNextBatch();
Expand Down Expand Up @@ -867,6 +867,10 @@ function createAbstractMapReduce(localDocName, mapper, reducer, ddocValidator) {
return httpQuery(db, fun, opts);
}

var updateViewOpts = {
changes_batch_size: db.__opts.view_update_changes_batch_size || CHANGES_BATCH_SIZE
};

if (typeof fun !== 'string') {
// temp_view
checkQueryParseError(opts, fun);
Expand All @@ -880,7 +884,7 @@ function createAbstractMapReduce(localDocName, mapper, reducer, ddocValidator) {
/* temporary */ true,
/* localDocName */ localDocName);
return createViewPromise.then(function (view) {
return fin(updateView(view).then(function () {
return fin(updateView(view, updateViewOpts).then(function () {
return queryView(view, opts);
}), function () {
return view.db.destroy();
Expand Down Expand Up @@ -917,12 +921,12 @@ function createAbstractMapReduce(localDocName, mapper, reducer, ddocValidator) {
if (opts.stale === 'ok' || opts.stale === 'update_after') {
if (opts.stale === 'update_after') {
nextTick(function () {
updateView(view);
updateView(view, updateViewOpts);
});
}
return queryView(view, opts);
} else { // stale not ok
return updateView(view).then(function () {
return updateView(view, updateViewOpts).then(function () {
return queryView(view, opts);
});
}
Expand Down

0 comments on commit 12ba6dd

Please sign in to comment.