简体   繁体   English

Django Registration登录的用户数

[英]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. 请。

Using the last logged in time doesn't work. 使用last logged in time不起作用。 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. 一种解决方案是创建一个具有登录会话的表,您可以将该会话ID存储在会话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. 一旦用户关闭了他/她的浏览器窗口,会话cookie就会过期,因此它可以让您准确估计人们何时登录。如果您确实想要存储整个会话持续时间,那么您还必须每次更新表格页面视图,用于存储用户上次活动的时间。 This would be slightly heavier for your database ofcourse. 对于您的数据库来说,这会稍微重一些。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM