i made an example repo to test this:
i am experiencing a headache while making a cursor_based pagination to sorted data
how do you guys handle this scenario?
i am building a blogging platform service for an exercise
and want to show trending posts ordered_by
their total_post_views
since there are too many posts, decided to introduce cursor_based pagination
however, total_post_views will be updated periodically (might be a day)
if the updates happen while any of user is navigating, (it means, query comes after an update)
{
posts(first: 5, after: "YXJyYXljb25uZWN0aW9uOjQ=", orderBy: {field: "total_post_views", sortOrder: "desc"}) {
edges {
node {
name
total_post_views
}
cursor
}
}
}
then, there is a possibility of skipping(not fetching) some posts (which have changed dramatically in total_post_views)
for example
before_update (order_by desc: total_post_views):
posts = [%{id: 10, total_post_views: 1000}, %{id: 9, total_post_views: 900}, ..., %{id: 1, total_post_views: 100}]
if i update post1 s total_post_views to 950
after_update (order_by desc: total_post_views):
posts = [%{id: 10, ...}, %{id: 1, total_post_views: 950}, ..., %{id: 2, total_post_views: 200}]
if a user have a cursor numbered 5, in the next pagination, user will have posts = [6, 5, 4, 3, 2]
after a uniq merge in frontend user is now have only [10, 9, 8, 7, 6, 5, 4, 3, 2]
post1 is skipped.