Commit cbbd1acb authored by Catalin Tomai's avatar Catalin Tomai
Browse files

Merge branch 'release-5.26' of https://github.com/mattermost/mattermost-server into release-5.26

parents 88377aae b873daf5
......@@ -2595,7 +2595,7 @@ func (a *App) ClearChannelMembersCache(channelID string) {
page := 0
for {
channelMembers, err := a.Srv().Store.Channel().GetMembers(channelID, page, perPage)
channelMembers, err := a.Srv().Store.Channel().GetMembers(channelID, page*perPage, perPage)
if err != nil {
a.Log().Warn("error clearing cache for channel members", mlog.String("channel_id", channelID))
break
......
......@@ -1877,6 +1877,28 @@ func TestMarkChannelsAsViewedPanic(t *testing.T) {
require.Nil(t, err)
}
func TestClearChannelMembersCache(t *testing.T) {
th := SetupWithStoreMock(t)
defer th.TearDown()
mockStore := th.App.Srv().Store.(*mocks.Store)
mockChannelStore := mocks.ChannelStore{}
cms := model.ChannelMembers{}
for i := 0; i < 200; i++ {
cms = append(cms, model.ChannelMember{
ChannelId: "1",
})
}
mockChannelStore.On("GetMembers", "channelID", 0, 100).Return(&cms, nil)
mockChannelStore.On("GetMembers", "channelID", 100, 100).Return(&model.ChannelMembers{
model.ChannelMember{
ChannelId: "1",
}}, nil)
mockStore.On("Channel").Return(&mockChannelStore)
th.App.ClearChannelMembersCache("channelID")
}
func TestSidebarCategory(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
......
......@@ -1643,7 +1643,7 @@ func (a *App) ClearTeamMembersCache(teamID string) {
page := 0
for {
teamMembers, err := a.Srv().Store.Team().GetMembers(teamID, page, perPage, nil)
teamMembers, err := a.Srv().Store.Team().GetMembers(teamID, page*perPage, perPage, nil)
if err != nil {
a.Log().Warn("error clearing cache for team members", mlog.String("team_id", teamID), mlog.String("err", err.Error()))
break
......
......@@ -11,7 +11,9 @@ import (
"testing"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/store/storetest/mocks"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
)
......@@ -1136,3 +1138,24 @@ func TestInvalidateAllEmailInvites(t *testing.T) {
_, err = th.App.Srv().Store.Token().GetByToken(t3.Token)
require.Nil(t, err)
}
func TestClearTeamMembersCache(t *testing.T) {
th := SetupWithStoreMock(t)
defer th.TearDown()
mockStore := th.App.Srv().Store.(*mocks.Store)
mockTeamStore := mocks.TeamStore{}
tms := []*model.TeamMember{}
for i := 0; i < 200; i++ {
tms = append(tms, &model.TeamMember{
TeamId: "1",
})
}
mockTeamStore.On("GetMembers", "teamID", 0, 100, mock.Anything).Return(tms, nil)
mockTeamStore.On("GetMembers", "teamID", 100, 100, mock.Anything).Return([]*model.TeamMember{{
TeamId: "1",
}}, nil)
mockStore.On("Team").Return(&mockTeamStore)
th.App.ClearTeamMembersCache("teamID")
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment