Pagination is slow
Postgres pagination using OFFSET
and LIMIT
gets slow with large offsets. We currently have a band-aid fix in place to block offsets larger than 250 (10 pages). But it would be nice to give users access to all of our previous content, and in a better way than we currently are.
What we should be doing is using cursor-based pagination, so instead of the Next Page button on the first page of new posts linking to /new/2
, we should have it link to /new?after_cursor=...
where the ... is a cursor value derived from the date and/or id of the last post on the page. This would mean users could bookmark a page of posts and have it always load the same posts, vs /new/2
which shows you whatever posts 26-50 are on any given day.
In addition to /new
we should use cursor-based pagination for /hot
and /top
routes. Using it on /hot
would also fix the problem, also present on /new
, where when loading page 2, you may be shown duplicate posts from the bottom of your page 1, if new posts were made while you were reading page 1.