Skip to content

Commit

Permalink
perf: use Promise.all on _find
Browse files Browse the repository at this point in the history
Close #1
  • Loading branch information
bwgjoseph committed Jun 5, 2021
1 parent c3468c8 commit 1456540
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# feathers-ottoman

[![GitHub license](https://img.shields.io/github/license/bwgjoseph/feathers-ottoman?style=flat-square)](https://github.com/bwgjoseph/feathers-ottoman/blob/master/LICENSE)
[![Download Status](https://img.shields.io/npm/dm/feathers-ottoman.svg?style=flat-square)](https://www.npmjs.com/package/feathers-ottoman)

__IMPORTANT__: This is still in early development stage, please report any issue found

This library is written against [ottoman-2.0.0-beta.1](https://github.com/couchbaselabs/node-ottoman). It is tested against [Couchbase 7.0 BETA](https://docs.couchbase.com/server/7.0/introduction/intro.html) which supports [scope and collection](https://docs.couchbase.com/server/7.0/learn/data/scopes-and-collections.html) and it should work with current version, [Couchbase 6.6](https://docs.couchbase.com/server/current/introduction/intro.html)
Expand Down
9 changes: 6 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,14 @@ class OttomanService<T = any> extends AdapterService<T> implements InternalServi
const cQuery = this._mapQueryOperator(query);
const cOptions = this._getOptions(filters, 'find');

const result = await this.Model.find(cQuery, cOptions);
const [result, total] = await Promise.all([
this.Model.find(cQuery, cOptions),
Object.keys(paginate).length > 0 ? this.Model.count(cQuery) : -1,
]);

if (Object.keys(paginate).length > 0) {
if (total >= 0) {
return {
total: await this.Model.count(cQuery),
total,
limit: filters.$limit,
skip: filters.$skip || 0,
data: result.rows,
Expand Down

0 comments on commit 1456540

Please sign in to comment.