Django 注册 登录用户数

发布于 2024-09-14 12:40:59 字数 160 浏览 1 评论 0原文

我有一个应用程序,我想在其中显示登录系统的用户数量。我试图确定最干净的方法来执行此操作,不会对系统造成很大的负载。

我知道系统会跟踪“上次登录时间”,所以我可以进行查询并汇总上次登录在给定时间内的用户数量?

有更好的解决方案吗??

有什么想法欢迎留言!!请。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

零度° 2024-09-21 12:40:59

使用上次登录时间不起作用。您的会话可能会持续数天/数周,因此您无法通过这种方式了解活跃用户的数量。

一种解决方案是创建一个包含登录会话的表,并将该会话 ID 存储在会话 cookie 中。一旦用户关闭他/她的浏览器窗口,会话 cookie 就会过期,因此它应该可以为您提供用户登录时间的相当准确的估计。如果您确实想要存储整个会话持续时间,那么您还必须更新该表页面视图存储用户上次活动的时间。当然,这对于您的数据库来说会稍微重一些。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文