The closest example to my case is a Django ajax chat application. The rooms need to keep a list of active users. Aside from displaying that list of users within the chat, a given room might have a maximum number of active users; new users need to be blocked from entering if there's no room.
Currently I have the chat client page calling a poll view every second via ajax. The poll view returns the text of the room. I figure poll can just also do some type of pinging -- adding users to an active_user M2M field on the Room object (I have all of this in place so far). What I need next is something that drops users from that active_user list after some kind of timeout.
I imagine there's two ways to do this, and I'm wondering which would be more efficient for an app that needs to be accurate to the second (or ten/fifteen seconds):
- Using cookies / sessions / middleware a la this thread (however it seems to me that this method wouldn't work for moment-to-moment info
- Another model, such as an explicit Users_Rooms 'through' table with a datetime field for the time that is updated upon creation and with every ping following, and write some function that cleans up the old ones
That's all I can think of. I'm just trying to figure out whether hitting mySQL every second for every user for every room is a good idea, and wondering if that second is indeed the best option for the task. Thanks!