Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions app/stats/online_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

// OnlineMap is an implementation of stats.OnlineMap.
type OnlineMap struct {
value int
ipList map[string]time.Time
access sync.RWMutex
lastCleanup time.Time
Expand All @@ -25,7 +24,7 @@ func NewOnlineMap() *OnlineMap {

// Count implements stats.OnlineMap.
func (c *OnlineMap) Count() int {
return c.value
return len(c.ipList)
}

// List implements stats.OnlineMap.
Expand All @@ -50,7 +49,6 @@ func (c *OnlineMap) AddIP(ip string) {
c.lastCleanup = time.Now()
}

c.value = len(list)
c.ipList = list
}

Expand Down Expand Up @@ -80,9 +78,8 @@ func (c *OnlineMap) RemoveExpiredIPs(list map[string]time.Time) map[string]time.
}

func (c *OnlineMap) IpTimeMap() map[string]time.Time {
list := c.ipList
if time.Since(c.lastCleanup) > c.cleanupPeriod {
list = c.RemoveExpiredIPs(list)
c.RemoveExpiredIPs(c.ipList)
c.lastCleanup = time.Now()
}

Expand Down
Loading