mislav / will_paginate

Pagination library for Rails and other Ruby applications
http://github.com/mislav/will_paginate/wikis
MIT License
5.71k stars 864 forks source link

Limit number of (pages of) results #657

Open JasonBarnabe opened 10 months ago

JasonBarnabe commented 10 months ago

Depending on the database engine and table size, queries may get more expensive as the OFFSET value gets larger. This results in the query for page 20, for example, executing considerably slower than querying page 2.

To deal with this, is there an option to limit the number of results, or the number of pages of results? For example, if I am showing 50 results per page, to never consider 21 a valid page when loading the results and to never offer a link to page 21, even if those results exist in the DB? In other words, only the first 1000 records would be accessible.

I know that simply redirecting any requests for page 21 back to page 1 or something accomplishes the first part, but then it would still be showing the link to page 21.

BishnuPandey commented 9 months ago

As, limiting the results is up to the service that consumes data, it is tricky. Would you please attach the screenshot and size of data the query returned. Also, the difference in time that 1st page take vs 20th page would be helpful. Hope that would help refine the problem.