diff --git a/internal/cache/cache.go b/internal/cache/cache.go index 3668607..e53742c 100644 --- a/internal/cache/cache.go +++ b/internal/cache/cache.go @@ -17,14 +17,12 @@ func (c *Cache) Create(query string, value uint) { c.items.Store(query, value) } -func (c *Cache) Exists(query string) (ok bool) { - _, ok = c.items.Load(query) - return -} - -func (c *Cache) Get(query string) uint { - i, _ := c.items.Load(query) - return i.(uint) +func (c *Cache) Get(query string) (uint, bool) { + i, ok := c.items.Load(query) + if !ok { + return 0, false + } + return i.(uint), true } // Invalidate is only needed when a member leaves and the search query reaches diff --git a/internal/ui/chat/composer.go b/internal/ui/chat/composer.go index 7888c18..89158f0 100644 --- a/internal/ui/chat/composer.go +++ b/internal/ui/chat/composer.go @@ -620,15 +620,15 @@ func channelHasUser(state *ningen.State, channelID discord.ChannelID, userID dis // It emits a follow-up suggestion message once results are loaded. func (c *composer) searchMember(gID discord.GuildID, name string) tview.Cmd { key := gID.String() + " " + name - if c.cache.Exists(key) { + if _, ok := c.cache.Get(key); ok { return nil } // If searching for "ab" returns less than SearchLimit, // then "abc" would not return anything new because we already searched // everything starting with "ab". This will still be true even if a new // member joins because arikawa loads new members into the state. - if k := key[:len(key)-1]; c.cache.Exists(k) { - if count := c.cache.Get(k); count < c.chat.state.MemberState.SearchLimit { + if count, ok := c.cache.Get(key[:len(key)-1]); ok { + if count < c.chat.state.MemberState.SearchLimit { c.cache.Create(key, count) return nil }