Fixing should send event removing extra go channel creation (#4942)

Этот коммит содержится в:
Corey Hulen
2017-01-03 11:45:45 -05:00
коммит произвёл enahum
родитель f94e220c88
Коммит f48c646208
4 изменённых файлов: 31 добавлений и 6 удалений

Просмотреть файл

@@ -839,6 +839,27 @@ func (us SqlChannelStore) InvalidateMemberCount(channelId string) {
channelMemberCountsCache.Remove(channelId)
}
func (s SqlChannelStore) GetMemberCountFromCache(channelId string) int64 {
metrics := einterfaces.GetMetricsInterface()
if cacheItem, ok := channelMemberCountsCache.Get(channelId); ok {
if metrics != nil {
metrics.IncrementMemCacheHitCounter("Channel Member Counts")
}
return cacheItem.(int64)
} else {
if metrics != nil {
metrics.IncrementMemCacheMissCounter("Channel Member Counts")
}
}
if result := <-s.GetMemberCount(channelId, true); result.Err != nil {
return 0
} else {
return result.Data.(int64)
}
}
func (s SqlChannelStore) GetMemberCount(channelId string, allowFromCache bool) StoreChannel {
storeChannel := make(StoreChannel, 1)
metrics := einterfaces.GetMetricsInterface()

Просмотреть файл

@@ -419,6 +419,14 @@ func TestChannelMemberStore(t *testing.T) {
t.Fatal("should have saved 2 members")
}
if store.Channel().GetMemberCountFromCache(o1.ChannelId) != 2 {
t.Fatal("should have saved 2 members")
}
if store.Channel().GetMemberCountFromCache("junk") != 0 {
t.Fatal("should have saved 0 members")
}
count = (<-store.Channel().GetMemberCount(o1.ChannelId, false)).Data.(int64)
if count != 2 {
t.Fatal("should have saved 2 members")

Просмотреть файл

@@ -108,6 +108,7 @@ type ChannelStore interface {
IsUserInChannelUseCache(userId string, channelId string) bool
GetMemberForPost(postId string, userId string) StoreChannel
InvalidateMemberCount(channelId string)
GetMemberCountFromCache(channelId string) int64
GetMemberCount(channelId string, allowFromCache bool) StoreChannel
RemoveMember(channelId string, userId string) StoreChannel
PermanentDeleteMembersByUser(userId string) StoreChannel