Reputation: 97997
If one wants to paginate results from a data source that supports pagination we have to go to a process of:
All this is works just fine not considering the fact that an operation may affect the backend system that screws up the pagination taking place. I am talking about someone inserting data between page fetches or deleting data.
page_size = 10;
get page 0 -> results from 0 to 9;
user inserts a record that due to the query being executed goes to page 0 - the one just shown;
get page 1 -> results from 10 to 19 - the first results on the page is the result on the old page 0.
The described behavior can cause confusion to the viewer. Do you know any practical solution to workaround this problem.
Upvotes: 1
Views: 1340
Reputation: 556
One option is to exclude new incoming data objects from the result. This could be done with the session start time. You could add this for example to your JWT and then have a similar behavior like Twitter (14 new Twitts).
Upvotes: 0
Reputation: 5033
As long as users understand that the underlying data is always changing, they won't be confused. So just do it the straightforward way.
You could cache the first few pages of the result and use that for subsequent views, but then the results will be out of sync with the database, which is even more confusing.
Upvotes: 0
Reputation: 14495
If the updates you are concerned with are primarily new insertions (for example, StackOverflow itself seems to suffer from this problem when paging through questions and new questions come in) one way to handle it is to capture a timestamp when you issue the first pagination query, and then limit the results of requests for subsequent pages to items which existed before that timestamp.
Upvotes: 0
Reputation: 63136
There are a few schools of thought o this.
.
Upvotes: 2