javascript - "Load more comments" link, get data in reversed order with infinite scroll pagination -
i trying create system of comments works in reversed order, recent older one, have issue logic , need help.
let's database contains total of 4 comments right now:
['comment1', 'comment2', 'comment3', 'comment4'];
let's client loads comments 2 per 2, ordered recent. send request server return 2 comments (limit 2) beginning (offset 0). far good, following:
['comment3', 'comment4']
while 2 comments displayed on client, user added comment in database. looks this:
['comment1', 'comment2', 'comment3', 'comment4', 'comment5'];
when client request load more comments, request limit 2, offset 2, following:
['comment2', 'comment3'];
here issue. comment 3 has been loaded , duplicated on client side. , comment 5 never loaded.
so question how can handled? number of comments changing, offsets become difficult manage.
i thinking of comments per date instead of offset, makes thing pretty complicated.
what best solution manage this?
thanks
keep track of comment 3's id, like:
select * comments id<x limit 2 offset 2
(assuming next want show comments 1 , 2. can tweak comparison achieve different results)
Comments
Post a Comment