Fix decoding active users from redis

(cherry picked from commit ae12871bd7)
This commit is contained in:
kolaente 2020-07-02 23:19:03 +02:00
parent d2d8c91c43
commit 9024fa6c3a
No known key found for this signature in database
GPG key ID: F40E70337AB24C9B

View file

@ -39,9 +39,11 @@ type ActiveUser struct {
LastSeen time.Time LastSeen time.Time
} }
type activeUsersMap map[int64]*ActiveUser
// ActiveUsersMap is the type used to save active users // ActiveUsersMap is the type used to save active users
type ActiveUsers struct { type ActiveUsers struct {
users map[int64]*ActiveUser users activeUsersMap
mutex *sync.Mutex mutex *sync.Mutex
} }
@ -59,7 +61,7 @@ func init() {
Help: "The currently active users on this node", Help: "The currently active users on this node",
}, func() float64 { }, func() float64 {
allActiveUsers, err := GetActiveUsers() allActiveUsers, err := getActiveUsers()
if err != nil { if err != nil {
log.Error(err.Error()) log.Error(err.Error())
} }
@ -67,7 +69,7 @@ func init() {
return 0 return 0
} }
activeUsersCount := 0 activeUsersCount := 0
for _, u := range allActiveUsers.users { for _, u := range allActiveUsers {
if time.Since(u.LastSeen) < SecondsUntilInactive*time.Second { if time.Since(u.LastSeen) < SecondsUntilInactive*time.Second {
activeUsersCount++ activeUsersCount++
} }
@ -87,8 +89,8 @@ func SetUserActive(a web.Auth) (err error) {
return PushActiveUsers() return PushActiveUsers()
} }
// GetActiveUsers returns the active users from redis // getActiveUsers returns the active users from redis
func GetActiveUsers() (users *ActiveUsers, err error) { func getActiveUsers() (users activeUsersMap, err error) {
activeUsersR, err := r.Get(ActiveUsersKey).Bytes() activeUsersR, err := r.Get(ActiveUsersKey).Bytes()
if err != nil { if err != nil {