Skip to content

Commit

Permalink
cache判断追加
Browse files Browse the repository at this point in the history
  • Loading branch information
walnuts1018 committed Mar 31, 2024
1 parent e29aa66 commit f49b994
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions slack/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,20 @@ func (c *Client) InviteUsersToChannels(ctx context.Context, channelIDs []string,
return nil
}

func (c *Client) GetPrefixedChannels(ctx context.Context, prefix string) (map[string]string, error) {
func (c *Client) GetPrefixedChannels(ctx context.Context, prefix string, mustIncludeChannelIDs ...string) (map[string]string, error) {
now := synchro.Now[tz.AsiaTokyo]()
if cache, ok := c.prefixedChannelCache[prefix]; ok && now.Before(c.prefixedChannelCacheExpiresAt[prefix]) {
return cache, nil
useCache := true
for _, mustIncludeChannelID := range mustIncludeChannelIDs {
if _, ok := cache[mustIncludeChannelID]; !ok {
useCache = false
break
}
}

if useCache {
return cache, nil
}
}

channels, err := c.GetPublicChannels(ctx)
Expand Down

0 comments on commit f49b994

Please sign in to comment.