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

It still fetches the count of all records even if I omit the with_total #132

Open
amrelhewy09 opened this issue Jun 16, 2023 · 1 comment

Comments

@amrelhewy09
Copy link

The pagination works but does the extra select COUNT(*) query for no reason.

chat_applications = RailsCursorPagination::Paginator.new(ChatApplication.all, first: 2, after: after).fetch

Why does this query do 2 extra queries?

chat_app                 |    (0.4ms)  SELECT COUNT(*) FROM `chat_applications` WHERE (`chat_applications`.`id` > 2)
chat_app                 |   ↳ app/controllers/api/v1/chat_applications_controller.rb:20:in `index'
chat_app                 |    (0.2ms)  SELECT COUNT(*) FROM `chat_applications`
@tomhughes
Copy link

This is because, depending on the direction, either previous_page? or next_page? will wind up querying the total even though it has been disable in the results.

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

No branches or pull requests

2 participants