Ignore empty channel lists

This commit is contained in:
Ken-Håvard Lieng 2020-05-11 14:13:36 +02:00
parent 8fa91ac470
commit 9581a63e81

View File

@ -18,6 +18,7 @@ type ChannelListIndex interface {
Finish()
Search(q string) []*ChannelListItem
SearchN(q string, start, n int) []*ChannelListItem
len() int
}
type MapChannelListIndex struct {
@ -74,6 +75,10 @@ func (idx *MapChannelListIndex) SearchN(q string, start, n int) []*ChannelListIt
return res[start:min(start+n, len(res))]
}
func (idx *MapChannelListIndex) len() int {
return len(idx.channels)
}
func min(x, y int) int {
if x < y {
return x
@ -142,12 +147,14 @@ func (m *ChannelIndexManager) Get(server string) (ChannelListIndex, bool) {
}
func (m *ChannelIndexManager) Set(server string, index ChannelListIndex) {
m.lock.Lock()
m.indexes[server] = &managedChannelIndex{
index: index,
updatedAt: time.Now(),
if index.len() > 0 {
m.lock.Lock()
m.indexes[server] = &managedChannelIndex{
index: index,
updatedAt: time.Now(),
}
m.lock.Unlock()
}
m.lock.Unlock()
}
func (m *ChannelIndexManager) timeoutUpdate(server string) {