DZ.
DZ.

Reputation: 3251

Django Registration Number of users logged in

I have an application where I would like to display the number of users that are logged into the system. Im trying to determine the cleanest way to do this that will not create a large load on the system.

I know that the system keeps track of the "last logged in time" So I could do a query and aggreate the number of users whose last login is within a given time?

Are there better solutions??

Any thoughts are welcome!! Please.

Upvotes: 4

Views: 276

Answers (1)

Wolph
Wolph

Reputation: 80061

Using the last logged in time doesn't work. Your sessions can last for days/weeks so you won't know the amount of active users that way.

One solution would be to create a table with login sessions where you store that session id in a session cookie. Session cookies expire once the user has closed his/her browser window so it should give you quite an accurate estimation of when people logged in. If you actually want to store the entire session duration, than you will also have to update the table with every page view to store the time that the user was last active. This would be slightly heavier for your database ofcourse.

Upvotes: 1

Related Questions