Commit 1eb77167 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Simplify group expiration.

parent be0f05da
...@@ -150,13 +150,17 @@ func (g *Group) ClientCount() int { ...@@ -150,13 +150,17 @@ func (g *Group) ClientCount() int {
return len(g.clients) return len(g.clients)
} }
func (g *Group) EmptyTime() time.Duration { func (g *Group) mayExpire() bool {
g.mu.Lock() g.mu.Lock()
defer g.mu.Unlock() defer g.mu.Unlock()
if g.description.Public {
return false
}
if len(g.clients) > 0 { if len(g.clients) > 0 {
return 0 return false
} }
return time.Since(g.timestamp) return time.Since(g.timestamp) > maxHistoryAge(g.description)
} }
var groups struct { var groups struct {
...@@ -1286,7 +1290,6 @@ func Update() { ...@@ -1286,7 +1290,6 @@ func Update() {
} }
names := GetNames() names := GetNames()
for _, name := range names { for _, name := range names {
g := Get(name) g := Get(name)
if g == nil { if g == nil {
...@@ -1294,13 +1297,13 @@ func Update() { ...@@ -1294,13 +1297,13 @@ func Update() {
} }
deleted := false deleted := false
historyAge := maxHistoryAge(g.description) if g.mayExpire() {
if !g.description.Public && g.EmptyTime() > historyAge {
// Delete checks if the group is still empty // Delete checks if the group is still empty
deleted = Delete(name) deleted = Delete(name)
} }
if !deleted && !descriptionUnchanged(name, g.description) { // update group description
if !deleted {
Add(name, nil) Add(name, nil)
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment