From ae12871bd79b67f9b90caacbee1c8dec1548c3e8 Mon Sep 17 00:00:00 2001 From: kolaente Date: Thu, 2 Jul 2020 23:19:03 +0200 Subject: [PATCH] Fix decoding active users from redis --- pkg/metrics/active_users.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pkg/metrics/active_users.go b/pkg/metrics/active_users.go index a232ad2b..08434c3f 100644 --- a/pkg/metrics/active_users.go +++ b/pkg/metrics/active_users.go @@ -39,9 +39,11 @@ type ActiveUser struct { LastSeen time.Time } +type activeUsersMap map[int64]*ActiveUser + // ActiveUsersMap is the type used to save active users type ActiveUsers struct { - users map[int64]*ActiveUser + users activeUsersMap mutex *sync.Mutex } @@ -59,7 +61,7 @@ func init() { Help: "The currently active users on this node", }, func() float64 { - allActiveUsers, err := GetActiveUsers() + allActiveUsers, err := getActiveUsers() if err != nil { log.Error(err.Error()) } @@ -67,7 +69,7 @@ func init() { return 0 } activeUsersCount := 0 - for _, u := range allActiveUsers.users { + for _, u := range allActiveUsers { if time.Since(u.LastSeen) < SecondsUntilInactive*time.Second { activeUsersCount++ } @@ -87,8 +89,8 @@ func SetUserActive(a web.Auth) (err error) { return PushActiveUsers() } -// GetActiveUsers returns the active users from redis -func GetActiveUsers() (users *ActiveUsers, err error) { +// getActiveUsers returns the active users from redis +func getActiveUsers() (users activeUsersMap, err error) { activeUsersR, err := r.Get(ActiveUsersKey).Bytes() if err != nil {