Timeout channel list updates
This commit is contained in:
parent
f8e12f5938
commit
9267c661dc
@ -100,6 +100,7 @@ func (c chanList) Swap(i, j int) {
|
||||
}
|
||||
|
||||
const ChannelListUpdateInterval = time.Hour * 24
|
||||
const ChannelListUpdateTimeout = time.Minute * 5
|
||||
|
||||
type ChannelIndexManager struct {
|
||||
indexes map[string]*managedChannelIndex
|
||||
@ -127,11 +128,13 @@ func (m *ChannelIndexManager) Get(server string) (ChannelListIndex, bool) {
|
||||
m.indexes[server] = &managedChannelIndex{
|
||||
updating: true,
|
||||
}
|
||||
go m.timeoutUpdate(server)
|
||||
return nil, true
|
||||
}
|
||||
|
||||
if !idx.updating && time.Since(idx.updatedAt) > ChannelListUpdateInterval {
|
||||
idx.updating = true
|
||||
go m.timeoutUpdate(server)
|
||||
return idx.index, true
|
||||
}
|
||||
|
||||
@ -146,3 +149,13 @@ func (m *ChannelIndexManager) Set(server string, index ChannelListIndex) {
|
||||
}
|
||||
m.lock.Unlock()
|
||||
}
|
||||
|
||||
func (m *ChannelIndexManager) timeoutUpdate(server string) {
|
||||
time.Sleep(ChannelListUpdateTimeout)
|
||||
|
||||
m.lock.Lock()
|
||||
if m.indexes[server].updating {
|
||||
m.indexes[server].updating = false
|
||||
}
|
||||
m.lock.Unlock()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user