6
votes

Hi I have a rails4 app using pagination with the will_paginate gem.

Is there a way to handle pagination with objects created very often? If you call the first page and right after that the page 2, considering new objects are created in the meantime, it is going to mess data (the offset in the sql request is for example going to call almost the same data as the first page).

Is there a way to use pagination with rapidly changing dynamic data?

Thx for your suggestions

1
How are you ordering the data? If the amount of total records is really volatile you can opt to not show the final page's number but an "end" indication. The offset shouldn't mess with anything if you're ordering by a create_at timestamp.azazeal
The pattern you're after is "cursor" pagination, and it isn't a feature of will_paginate. However, you could implement it yourself fairly easily - add the current date as a parameter to each pagination link, and then filter your ActiveRecord relation to only include records created before that date, if the parameter is present. See sitepoint.com/paginating-real-time-data-cursor-based-pagination for a good description.robomc

1 Answers

0
votes

Also, you could use the cursor gem