MySQL Query Result Offset With Limit With New Result Possibility?
I'm working on an application that uses a scroll load system of 20 or so
results loading into a feed at a time as you scroll. This feed consists of
constantly added user generated content. Which means the result set can
change per query that is offset by X.
So let's say we load 20 results, then scroll, another 20, and then before
scrolling more to load the next 20, another user has uploaded a new piece
of content, which effectively would present a duplicate in the next set of
20 results for the feed because we're using OFFSET to get additional
results, and the total result set is getting shifted by 1 with this
addition of new content that falls into the conditions of the query.
What is the best and most efficient way around this? We've dabbled with
using the id of a row in a where condition to prevent duplicate results,
and only using limit without offset for new results fetched.. so we could
do WHERE id < 170, WHERE id < 150, WHERE id < 130, etc.. to control and
prevent duplciates... HOWEVER, this does not work in every possible
scenario as our result sets aren't always ordered with the id column
ordered by DESC..
Soo.. what other options are there?..
No comments:
Post a Comment