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