The closest example to my case is the Django ajax chat application. The rooms should have a list of active users. In addition to displaying this list of users in chat, this room can have a maximum number of active users; new users should be blocked from entering if there is no space.
I currently have a chat client page that invokes a poll view every second through ajax. The polling window displays the text of the room. I believe that polling can also do some type of pinging - adding users to the active_user M2M field on the Room object (I have it all in place so far). Now I need something that throws users from this active_user list after some timeout.
I assume there are two ways to do this, and I wonder what will be more efficient for an application that needs to be accurate for a second (or ten / fifteen seconds):
- Using cookies / sessions / middleware a la this stream (however it seems to me that this method will not work for instant information
- Another model, such as an explicit Users_Rooms table through a table with a datetime field for the time that is updated after creation and with each subsequent ping, and writes some function that clears the old
That’s all I can think of. I'm just trying to understand if mySQL defeat every second for every user for every room, this is a good idea and I wonder if this second is really the best option for this task. Thanks!
source share