MM42267: Add member count in the browse channel modal (#23800)
* add base for calling the endpoint * add endpoint and handler * update store and layers * call the endpoint * align types * update app layers * generate mocks * complete handler * finish store query * add todos * add ui for member count * add selector * add a todo * add cache layer * optimize calls in FE * handle invalidation of the cache * fix go style * fix test * use existing channel layer count * fix import error * delete unnecessary code * write tests for channel cache layer * fix testname * fix mocks * fix cache layer test * fix a test * really fix the test * write more tests for server * address PR comments * remove comment * rename more_channels to browse_channels * fix style * update snapshot * add translations * Revert "add translations" This reverts commit 56476a5dabe357703ef02be9a38b3e88f5c8b1e7. * add only related translations * address PR review points * add test * fix test --------- Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
4803889158
Коммит
628273d98d
@@ -225,6 +225,35 @@ func (s LocalCacheChannelStore) SaveMultipleMembers(members []*model.ChannelMemb
|
||||
return members, nil
|
||||
}
|
||||
|
||||
func (s LocalCacheChannelStore) GetChannelsMemberCount(channelIDs []string) (_ map[string]int64, err error) {
|
||||
counts := make(map[string]int64)
|
||||
remainingChannels := make([]string, 0)
|
||||
|
||||
for _, channelID := range channelIDs {
|
||||
var cacheItem int64
|
||||
err := s.rootStore.doStandardReadCache(s.rootStore.channelMemberCountsCache, channelID, &cacheItem)
|
||||
if err == nil {
|
||||
counts[channelID] = cacheItem
|
||||
} else {
|
||||
remainingChannels = append(remainingChannels, channelID)
|
||||
}
|
||||
}
|
||||
|
||||
if len(remainingChannels) > 0 {
|
||||
remainingChannels, err := s.ChannelStore.GetChannelsMemberCount(remainingChannels)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for id, count := range remainingChannels {
|
||||
s.rootStore.doStandardAddToCache(s.rootStore.channelMemberCountsCache, id, count)
|
||||
counts[id] = count
|
||||
}
|
||||
}
|
||||
|
||||
return counts, nil
|
||||
}
|
||||
|
||||
func (s LocalCacheChannelStore) UpdateMember(member *model.ChannelMember) (*model.ChannelMember, error) {
|
||||
member, err := s.ChannelStore.UpdateMember(member)
|
||||
if err != nil {
|
||||
|
||||
@@ -104,6 +104,43 @@ func TestChannelStoreChannelMemberCountsCache(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestChannelStoreChannelsMemberCountCache(t *testing.T) {
|
||||
channelsCountResult := map[string]int64{
|
||||
"channel1": 10,
|
||||
"channel2": 20,
|
||||
}
|
||||
|
||||
t.Run("first call not cached, second cached and returning same data", func(t *testing.T) {
|
||||
mockStore := getMockStore()
|
||||
mockCacheProvider := getMockCacheProvider()
|
||||
cachedStore, err := NewLocalCacheLayer(mockStore, nil, nil, mockCacheProvider)
|
||||
require.NoError(t, err)
|
||||
|
||||
channelsCount, err := cachedStore.Channel().GetChannelsMemberCount([]string{"channel1", "channel2"})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, channelsCount, channelsCountResult)
|
||||
mockStore.Channel().(*mocks.ChannelStore).AssertNumberOfCalls(t, "GetChannelsMemberCount", 1)
|
||||
channelsCount, err = cachedStore.Channel().GetChannelsMemberCount([]string{"channel1", "channel2"})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, channelsCount, channelsCountResult)
|
||||
mockStore.Channel().(*mocks.ChannelStore).AssertNumberOfCalls(t, "GetChannelsMemberCount", 1)
|
||||
})
|
||||
|
||||
t.Run("first call not cached, invalidate cache, second call not cached", func(t *testing.T) {
|
||||
mockStore := getMockStore()
|
||||
mockCacheProvider := getMockCacheProvider()
|
||||
cachedStore, err := NewLocalCacheLayer(mockStore, nil, nil, mockCacheProvider)
|
||||
require.NoError(t, err)
|
||||
|
||||
cachedStore.Channel().GetChannelsMemberCount([]string{"channel1", "channel2"})
|
||||
mockStore.Channel().(*mocks.ChannelStore).AssertNumberOfCalls(t, "GetChannelsMemberCount", 1)
|
||||
cachedStore.Channel().InvalidateMemberCount("channel1")
|
||||
cachedStore.Channel().InvalidateMemberCount("channel2")
|
||||
cachedStore.Channel().GetChannelsMemberCount([]string{"channel1", "channel2"})
|
||||
mockStore.Channel().(*mocks.ChannelStore).AssertNumberOfCalls(t, "GetChannelsMemberCount", 2)
|
||||
})
|
||||
}
|
||||
|
||||
func TestChannelStoreChannelPinnedPostsCountsCache(t *testing.T) {
|
||||
countResult := int64(10)
|
||||
|
||||
|
||||
@@ -100,6 +100,12 @@ func getMockStore() *mocks.Store {
|
||||
mockChannelStore.On("Get", channelId, false).Return(&fakeChannelId, nil)
|
||||
mockStore.On("Channel").Return(&mockChannelStore)
|
||||
|
||||
mockChannelsMemberCount := map[string]int64{
|
||||
"channel1": 10,
|
||||
"channel2": 20,
|
||||
}
|
||||
mockChannelStore.On("GetChannelsMemberCount", []string{"channel1", "channel2"}).Return(mockChannelsMemberCount, nil)
|
||||
|
||||
mockPinnedPostsCount := int64(10)
|
||||
mockChannelStore.On("GetPinnedPostCount", "id", true).Return(mockPinnedPostsCount, nil)
|
||||
mockChannelStore.On("GetPinnedPostCount", "id", false).Return(mockPinnedPostsCount, nil)
|
||||
|
||||
Ссылка в новой задаче
Block a user