MM-60606: Respect allowFromCache flag in Channelstore.GetMany (#28290)
Setting the flag to false never worked, and it was never caught because there wasn't an instance when this method was called with allowFromCache=false. https://mattermost.atlassian.net/browse/MM-60606 ```release-note NONE ```
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
9447cb9074
Коммит
5a511a14ee
@@ -211,7 +211,6 @@ func (s LocalCacheChannelStore) GetPinnedPostCount(channelId string, allowFromCa
|
|||||||
}
|
}
|
||||||
|
|
||||||
count, err := s.ChannelStore.GetPinnedPostCount(channelId, allowFromCache)
|
count, err := s.ChannelStore.GetPinnedPostCount(channelId, allowFromCache)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
@@ -244,22 +243,24 @@ func (s LocalCacheChannelStore) GetMany(ids []string, allowFromCache bool) (mode
|
|||||||
var foundChannels []*model.Channel
|
var foundChannels []*model.Channel
|
||||||
var channelsToQuery []string
|
var channelsToQuery []string
|
||||||
|
|
||||||
if allowFromCache {
|
if !allowFromCache {
|
||||||
toPass := allocateCacheTargets[*model.Channel](len(ids))
|
return s.ChannelStore.GetMany(ids, allowFromCache)
|
||||||
errs := s.rootStore.doMultiReadCache(s.rootStore.roleCache, ids, toPass)
|
}
|
||||||
for i, err := range errs {
|
|
||||||
if err != nil {
|
toPass := allocateCacheTargets[*model.Channel](len(ids))
|
||||||
if err != cache.ErrKeyNotFound {
|
errs := s.rootStore.doMultiReadCache(s.rootStore.roleCache, ids, toPass)
|
||||||
s.rootStore.logger.Warn("Error in Channelstore.GetMany: ", mlog.Err(err))
|
for i, err := range errs {
|
||||||
}
|
if err != nil {
|
||||||
channelsToQuery = append(channelsToQuery, ids[i])
|
if err != cache.ErrKeyNotFound {
|
||||||
|
s.rootStore.logger.Warn("Error in Channelstore.GetMany: ", mlog.Err(err))
|
||||||
|
}
|
||||||
|
channelsToQuery = append(channelsToQuery, ids[i])
|
||||||
|
} else {
|
||||||
|
gotChannel := *(toPass[i].(**model.Channel))
|
||||||
|
if gotChannel != nil {
|
||||||
|
foundChannels = append(foundChannels, gotChannel)
|
||||||
} else {
|
} else {
|
||||||
gotChannel := *(toPass[i].(**model.Channel))
|
s.rootStore.logger.Warn("Found nil channel in GetMany. This is not expected")
|
||||||
if gotChannel != nil {
|
|
||||||
foundChannels = append(foundChannels, gotChannel)
|
|
||||||
} else {
|
|
||||||
s.rootStore.logger.Warn("Found nil channel in GetMany. This is not expected")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -391,6 +391,19 @@ func TestChannelStoreGetManyCache(t *testing.T) {
|
|||||||
assert.ElementsMatch(t, model.ChannelList{&fakeChannel, &fakeChannel2}, channels)
|
assert.ElementsMatch(t, model.ChannelList{&fakeChannel, &fakeChannel2}, channels)
|
||||||
mockStore.Channel().(*mocks.ChannelStore).AssertNumberOfCalls(t, "GetMany", 2)
|
mockStore.Channel().(*mocks.ChannelStore).AssertNumberOfCalls(t, "GetMany", 2)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("passing allowCache=false should bypass cache", func(t *testing.T) {
|
||||||
|
mockStore := getMockStore(t)
|
||||||
|
mockCacheProvider := getMockCacheProvider()
|
||||||
|
cachedStore, err := NewLocalCacheLayer(mockStore, nil, nil, mockCacheProvider, logger)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
fakeChannel := model.Channel{Id: "channel1", Name: "channel1-name"}
|
||||||
|
channels, err := cachedStore.Channel().GetMany([]string{fakeChannel.Id}, false)
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.ElementsMatch(t, model.ChannelList{&fakeChannel}, channels)
|
||||||
|
mockStore.Channel().(*mocks.ChannelStore).AssertNumberOfCalls(t, "GetMany", 1)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestChannelStoreGetByNamesCache(t *testing.T) {
|
func TestChannelStoreGetByNamesCache(t *testing.T) {
|
||||||
|
|||||||
@@ -104,6 +104,7 @@ func getMockStore(t *testing.T) *mocks.Store {
|
|||||||
mockChannelStore.On("Get", channelId, true).Return(&fakeChannel1, nil)
|
mockChannelStore.On("Get", channelId, true).Return(&fakeChannel1, nil)
|
||||||
mockChannelStore.On("Get", channelId, false).Return(&fakeChannel1, nil)
|
mockChannelStore.On("Get", channelId, false).Return(&fakeChannel1, nil)
|
||||||
mockChannelStore.On("GetMany", []string{channelId}, true).Return(model.ChannelList{&fakeChannel1}, nil)
|
mockChannelStore.On("GetMany", []string{channelId}, true).Return(model.ChannelList{&fakeChannel1}, nil)
|
||||||
|
mockChannelStore.On("GetMany", []string{channelId}, false).Return(model.ChannelList{&fakeChannel1}, nil)
|
||||||
mockChannelStore.On("GetMany", []string{fakeChannel2.Id}, true).Return(model.ChannelList{&fakeChannel2}, nil)
|
mockChannelStore.On("GetMany", []string{fakeChannel2.Id}, true).Return(model.ChannelList{&fakeChannel2}, nil)
|
||||||
mockChannelStore.On("GetByNames", "team1", []string{fakeChannel1.Name}, true).Return([]*model.Channel{&fakeChannel1}, nil)
|
mockChannelStore.On("GetByNames", "team1", []string{fakeChannel1.Name}, true).Return([]*model.Channel{&fakeChannel1}, nil)
|
||||||
mockChannelStore.On("GetByNames", "team1", []string{fakeChannel2.Name}, true).Return([]*model.Channel{&fakeChannel2}, nil)
|
mockChannelStore.On("GetByNames", "team1", []string{fakeChannel2.Name}, true).Return([]*model.Channel{&fakeChannel2}, nil)
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user