Django Registration Number of registered users

I have an application in which I would like to display the number of users who are logged in. I am trying to determine the cleanest way to do this, which will not create a large load on the system.

I know that the system tracks the "last recorded time." So I could make a request and increase the number of users whose last login is at a given time?

Are there any better solutions?

Any thoughts are welcome! You are welcome.

+4
source share
1 answer

Using last logged in time does not work. Your sessions can last several days / weeks, so you won’t know the number of active users in this way.

One solution would be to create a table with login sessions in which you store this session identifier in a session cookie. Session cookies terminate as soon as the user closes his browser window so that he gives you a fairly accurate estimate of when users are logged in. If you really want to keep the entire duration of the session, you will also have to update the table with each to save the time the user last used it. It will be a little harder for your database, of course.

+1
source

All Articles