So it’s not a complicated matter at all, but was wondering how the Stackoverflow community would tackle this.
I wrote a facebook-style wall type thing where users enter their “status”, it gets processed via jQuery Post and upon success returns a success message.
Prepending the new message to the Wall Stream would make sense, however, if another user had entered a message before the submission it would fail to show the correct time sequence…
I guess my question is this.
Should I query the latest Wall Messages inside the PHP file and echo back the entire result? That way when jQuery receives the callback it can delete whatever is in the Wall Stream and update with the new content?
I am assuming a bit on the details and purpose of your app but I probably would not bother doing anything fancy. Typing a status is pretty quick and the probability someone else beat you to the race is somewhat of an edge case yet adds complexity and a database performance hit. Also the error of showing the wrong time sequence in my opinion is forgivable in the rare case that it does occur and the user notices. There’s probably bigger fish to fry somewhere else in your app.
If the nature of the app or site makes correctness important, then a possible solution is to post the id of the most recent message that has already been loaded on the client side so that the server can respond with the contents/details of messages posted after that id so the new messages can be rendered for the client. I would post an id instead of a timestamp so that there’s no need for synchronization between client and server time.