Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: when pagination is false, skip the execution of count #194

Merged
merged 1 commit into from
Jul 15, 2023

Conversation

Seitk
Copy link
Contributor

@Seitk Seitk commented Jul 14, 2023

Based on the documentation

If pagination is set to false, it will return all docs without adding limit condition

When we set pagination is false we do expect to all documents are returned, we can simply use the length of docs as countDocuments is considered costly in general

yarn test
yarn run v1.22.19
$ npm run build

> mongoose-paginate-v2@1.7.1 build
> babel src -d dist

Successfully compiled 3 files with Babel (226ms).
$ ./node_modules/.bin/mocha tests/*.js -R spec --ui bdd --timeout 9999999


  mongoose-paginate
(node:7214) DeprecationWarning: collection.ensureIndex is deprecated. Use createIndexes instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
    ✓ promise return test
    ✓ callback test
    ✓ with page and limit
    ✓ first page with page and limit, limit > doc.length
    ✓ first page with page and limit, limit > doc.length, offset by one
    ✓ first page with page and limit
    ✓ last page with page and limit
    ✓ with offset and limit (not page)
    ✓ with offset and limit (not page) condition: offset > 0 < limit
    ✓ with limit=0 (metadata only)
    ✓ with empty custom labels
    ✓ with custom labels
    ✓ with custom Meta label
    ✓ Sub documents pagination
    ✓ all data (without pagination)
    ✓ estimated count works
    ✓ count Custom Fn works
    ✓ count Custom Fn with Promise return works
    ✓ pagination=false, limit/page=undefined -> return all docs
    ✓ PaginationParameters-helper -> number type options work
    ✓ PaginationParameters-helper -> (JSON) object type options work
    ✓ PaginationParameters-helper -> boolean options work
    ✓ PaginationParameters-helper -> string options work


  23 passing (228ms)

✨  Done in 1.42s.

@Seitk Seitk force-pushed the pagination-false-without-count branch from 63d2926 to 1172d7d Compare July 14, 2023 05:45
@Seitk Seitk changed the title fix: respect pagination false and do not set count promise fix: when pagination is false, skip the execution of count Jul 14, 2023
@Seitk Seitk force-pushed the pagination-false-without-count branch from 1172d7d to 6fc4916 Compare July 14, 2023 06:53
Copy link
Owner

@aravindnc aravindnc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@aravindnc aravindnc merged commit 5d759f6 into aravindnc:master Jul 15, 2023
@Seitk Seitk deleted the pagination-false-without-count branch July 19, 2023 06:36
@Seitk
Copy link
Contributor Author

Seitk commented Jul 19, 2023

Hi @aravindnc could you publish the fix to npm 🙏🏻

@aravindnc
Copy link
Owner

aravindnc commented Jul 19, 2023

Hi @aravindnc could you publish the fix to npm 🙏🏻

@Seitk
1.7.2 is published. Sorry for the delay. And thanks for the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants