From 9581a63e8153169710e05664ad034c1cd2985d44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ken-H=C3=A5vard=20Lieng?= Date: Mon, 11 May 2020 14:13:36 +0200 Subject: [PATCH] Ignore empty channel lists --- storage/channel_index.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/storage/channel_index.go b/storage/channel_index.go index ad11be5e..3c4f5530 100644 --- a/storage/channel_index.go +++ b/storage/channel_index.go @@ -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) {