olavim / objection-cursor

Cursor based pagination plugin for Objection.js
MIT License
30 stars 8 forks source link

Could there be a reason some records are skipped? #36

Closed Go1dExperience closed 2 years ago

Go1dExperience commented 2 years ago

objection-cursor: 1.2.5 objection: 1.6.11.

Hi, thank you very much for creating this wonderful library. In our projects, we notice that sometimes it will skip some records. Most of the time it will probably be about 5, 10 records, but in a special case where I'm ordering by status(1,2,3(, it skips 700 records and jump directly from first page to last page. Unfortunately I cannot share a code because it's very huge, but just want to know your opinion, because when I bring the query generated by the library to SQL, then it will give the correct number of records, so I believe it might be something with the library itself. Have you encountered a similar situation? Thank you.

olavim commented 2 years ago

It sounds like you are ordering by a column set that is not unique between rows. The status column doesn't sound like it holds unique values, at least. If your model has some unique id column, try ordering with both status and id.

With cursor-based pagination it's important that we can say something like "give me 15 rows after this row", and it's therefore important that we can uniquely identify a specific row. If your ordering is based on a column set that can occur multiple times in a table, we cannot know which of those rows you meant exactly.

Go1dExperience commented 2 years ago

Yep that's exactly the problem. Don't know how I could miss that, but thank you very much for you help. Closing the issue now.