4 ms·
On the frontend would one store page=1,page=2 or page=user_id(10000th),page=user_id(20000th) ?
by wolco 9y ago
On the frontend would one store page=1,page=2 or page=user_id(10000th),page=user_id(20000th)
?
- alvil 9y agoWith this approach you can't have page numbers on the front-end, just first, prev, next and maybe last. You can't jump to particular page. It is old technique and I like it, but if it would be usable it would be used by everyone but it is not.
- ngrilly 9y agoWhat is the purpose of having pages numbers and jumping to a particular page?
- thriftwy 9y agoFor example you have a forum post with 1000 messages starting in 2007, and you are dying to know what happened in the discourse in 2011. So basically you need to jump in the middle by bisection. 1000 is tiny by DB standards but solutions like this one are often bolted without considerations.
- ngrilly 9y agoThat's a great example. I understand the use case now. I note this use case can be solved using keyset pagination instead of offset/limit, because the ordering of messages is stable: messages are never inserted in the middle of the list; they are appended at the end. We can attribute a number to each message, and use this message to filter and sort.
- thriftwy 9y agoBut what if a message gets deleted from middle of the list? This happens with forum messages.
- ngrilly 9y agoYou keep it and mark it "deleted", and you show "deleted" in place of the message. This is what most forums do already, independently of the underlying pagination mechanism.
- thriftwy 9y agoSo basically I'm pretty sure now that we need a new kind of SQL INDEX, as in, pagination index. To do that aforedescribed accounting for us, and more.
- majewsky 9y agoSome APIs expose the key offset mechanism. For example, in most OpenStack APIs, instead of ?page=2, you say ?marker=12345, where 12345 is the ID of the last object on the previous page. The end of the pagination is signalled by an empty response.
- pdkl95 9y agoHN uses this technique for each user's comment list ("threads" link in the header). The "next" link at the bottom of each page is /threads?id=${USER_NAME}&next=${NEXT_COMMENT_ID}