tags:

views:

106

answers:

4

Feel free to edit the title if you know how to formulate the question better. (Tagging is a problem as well.) The problem may be too difficult in this general form, so let us consider a concrete example.

You get a screenful of stackoverflow questions by requesting /questions ?sort=newest page. Next page link leads to /questions?page=2 &sort=newest. I suppose that at server side, the request is translated into an SQL query with LIMIT clause. Problem with this approach is, that if new question were added while user browses first page, his second page will start with some questions he already saw. (If he has 10 question per page, and 10 new questions happened to be added, he’ll get exactly the same content second time!)

Is there an elegant way to solve this common problem? I realize that it is not that big a problem, at least not for stackoverflow, but still.

The best idea I have (apart from storing request history per client) is to use /questions?answer_id=NNN format. Server returns a page that starts with the requested answer, and puts the id of the first answer on the next page into next page link. There must be a way to write SQL for that, right?

Is it how it usually done? Or there is a better way?

A: 

Most web sites I've seen don't solve this problem - they show you a page including some content you've already seen.

You might consider that a feature - when you click "next" and see some content you're seen before, it's a signal that you want to go back to the front again because there's some new content.

Paul Tomblin
A: 

Tag each question with its time entered into the database, carry the time the frontpage was last loaded as a cookie or part of the URL, and limit the search to items n through n+displaynum as you go forward.

But I wouldn't bother. This behavior is uniform enough that most users expect it, and it serves as a flag for when new data is becoming available. You can even open a new tab/window that starts back at the top of the list to see what has come up.

dmckee
A: 

I believe the SQL (for MySQL) would be:

SELECT * 
FROM   entries 
WHERE  entry_id >= @last_viewed_entry_id 
ORDER BY entry_id 
LIMIT 50
AJ
+1  A: 

This can't be done an easy way. For instance, the "Unanswered" list here at stackoverflow is sorted by number of votes. So if you'd save the last ID of the page you're viewing (in a cookie, request, session, whereever) and someone upvotes a post while you're browsing page 2, page 3 isn't complete since the recently upvoted post could have been moved to page 1 or 2.

Only way to do it is to load the complete list in someones session. Please don't...

As already mentioned, let's hope people are used to this by now.

Casper
totally agree. moreover, if you have so much output, it's better to go with a report or with better filtering options for the searches. If you have more than one page of relevant web output, the layout design probably needs a refactor
Lorenzo Boccaccia