Skip to content

Commit

Permalink
fix: make queryViewByUser more efficient
Browse files Browse the repository at this point in the history
limit the potential number of requests made to couchdb by gradually increasing the limit used for each request

Closes #30
  • Loading branch information
stropitek committed Sep 8, 2016
1 parent 5555578 commit d228f44
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ class Couch {

async queryViewByUser(user, view, options, rights) {
debug(`queryViewByUser (${user}, ${view})`);
options = options || {};
options = Object.assign({}, options);
options.include_docs = true;
options.reduce = false;
options.skip = 0;
Expand All @@ -334,13 +334,13 @@ class Couch {
if (!options.limit) return rows;

// Concatenate
limit = options.limit;
options.skip += limit;
options.skip += options.limit;
options.limit = options.limit * 2;
cumRows = cumRows.concat(rows);
}

// Get rid of extra rows
return cumRows.filter((r, idx) => idx < options.limit);
return cumRows.filter((r, idx) => idx < limit);
}

async getEntriesByUserAndRights(user, rights, options = {}) {
Expand Down

0 comments on commit d228f44

Please sign in to comment.