Fix decoding active users from redis
This commit is contained in:
parent
7141050f8b
commit
ae12871bd7
1 changed files with 7 additions and 5 deletions
|
@ -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 {
|
||||||
|
|
Loading…
Reference in a new issue