views:

32

answers:

2

Currently,I do it in a straightforward way, that is, when user loads every page, we check once. we check it by directly query the private_message table.

Any better/efficiency way?

+1  A: 

use ajax to periodically check for new messages. but that depends on your page—if there are a lot of page requests/reloads your solution works as well

knittl
thanks, knitl.
lovespring
A: 

A possibility would be an additional event table where you're storing events that you want to warn the user about. This would be more than just a private message, though. But in general, whenever there's a private message, you add an event with a short description and an URL to the new message. If something else happens then you can add that too as an event. For example, if a friend comes online, you could add a "friend online" event. (Possibly followed by a "friend offline" event sooner or later.)

From this event table, you could count the number of events and just display the most recent one. Since it would contain multiple different notifications you would now have one generic way to deal with them. And if a user clicks one, it's removed again. Or the user goes to the "Events" page and deletes them all.

When to check for new events? Either through Ajax or with every page request. The Ajax solution would be nicer for the users but also eat more bandwidth since it keeps checking for new info. But with only a few visitors, it's unlikely that they'll receive many new messages. Having a "live" warning about new messages wouldn't be a real requirement in that case. So in both scenario's, an update per page request should be just fine... (Unless you have unlimited bandwidth.)

Workshop Alex