rails_cursor_pagination icon indicating copy to clipboard operation
rails_cursor_pagination copied to clipboard

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

Open amrelhewy09 opened this issue 2 years ago • 1 comments
trafficstars

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`

amrelhewy09 avatar Jun 16 '23 12:06 amrelhewy09

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.

tomhughes avatar Jul 23 '23 18:07 tomhughes