MM-56879: Migrate caches from store layer to cache layer (#26255)
There were 3 remaining caches which were there in the store layer. We migrate them to make the store layer fully free from any caches. https://mattermost.atlassian.net/browse/MM-56879 ```release-note NONE ``` Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
d7a77d8c42
Коммит
204c728b08
@@ -1417,7 +1417,7 @@ func (a *App) getChannelsForPosts(teams map[string]*model.Team, data []*imports.
|
||||
channelName := strings.ToLower(*postData.Channel)
|
||||
if channel, ok := teamChannels[teamName][channelName]; !ok || channel == nil {
|
||||
var err error
|
||||
channel, err = a.Srv().Store().Channel().GetByName(teams[teamName].Id, *postData.Channel, true)
|
||||
channel, err = a.Srv().Store().Channel().GetByNameIncludeDeleted(teams[teamName].Id, *postData.Channel, true)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("BulkImport", "app.import.import_post.channel_not_found.error", map[string]any{"ChannelName": *postData.Channel}, "", http.StatusBadRequest).Wrap(err)
|
||||
}
|
||||
|
||||
@@ -17,9 +17,6 @@ func (ps *PlatformService) RegisterClusterHandlers() {
|
||||
ps.clusterIFace.RegisterClusterMessageHandler(model.ClusterEventPublish, ps.ClusterPublishHandler)
|
||||
ps.clusterIFace.RegisterClusterMessageHandler(model.ClusterEventUpdateStatus, ps.ClusterUpdateStatusHandler)
|
||||
ps.clusterIFace.RegisterClusterMessageHandler(model.ClusterEventInvalidateAllCaches, ps.ClusterInvalidateAllCachesHandler)
|
||||
ps.clusterIFace.RegisterClusterMessageHandler(model.ClusterEventInvalidateCacheForChannelMembersNotifyProps, ps.clusterInvalidateCacheForChannelMembersNotifyPropHandler)
|
||||
ps.clusterIFace.RegisterClusterMessageHandler(model.ClusterEventInvalidateCacheForChannelByName, ps.clusterInvalidateCacheForChannelByNameHandler)
|
||||
ps.clusterIFace.RegisterClusterMessageHandler(model.ClusterEventInvalidateCacheForUser, ps.clusterInvalidateCacheForUserHandler)
|
||||
ps.clusterIFace.RegisterClusterMessageHandler(model.ClusterEventInvalidateCacheForUserTeams, ps.clusterInvalidateCacheForUserTeamsHandler)
|
||||
ps.clusterIFace.RegisterClusterMessageHandler(model.ClusterEventBusyStateChanged, ps.clusterBusyStateChgHandler)
|
||||
ps.clusterIFace.RegisterClusterMessageHandler(model.ClusterEventClearSessionCacheForUser, ps.clusterClearSessionCacheForUserHandler)
|
||||
@@ -70,18 +67,6 @@ func (ps *PlatformService) ClusterInvalidateAllCachesHandler(msg *model.ClusterM
|
||||
ps.InvalidateAllCachesSkipSend()
|
||||
}
|
||||
|
||||
func (ps *PlatformService) clusterInvalidateCacheForChannelMembersNotifyPropHandler(msg *model.ClusterMessage) {
|
||||
ps.invalidateCacheForChannelMembersNotifyPropsSkipClusterSend(string(msg.Data))
|
||||
}
|
||||
|
||||
func (ps *PlatformService) clusterInvalidateCacheForChannelByNameHandler(msg *model.ClusterMessage) {
|
||||
ps.invalidateCacheForChannelByNameSkipClusterSend(msg.Props["id"], msg.Props["name"])
|
||||
}
|
||||
|
||||
func (ps *PlatformService) clusterInvalidateCacheForUserHandler(msg *model.ClusterMessage) {
|
||||
ps.InvalidateCacheForUserSkipClusterSend(string(msg.Data))
|
||||
}
|
||||
|
||||
func (ps *PlatformService) clusterInvalidateCacheForUserTeamsHandler(msg *model.ClusterMessage) {
|
||||
ps.invalidateWebConnSessionCacheForUser(string(msg.Data))
|
||||
}
|
||||
@@ -118,23 +103,6 @@ func (ps *PlatformService) clusterBusyStateChgHandler(msg *model.ClusterMessage)
|
||||
}
|
||||
}
|
||||
|
||||
func (ps *PlatformService) invalidateCacheForChannelMembersNotifyPropsSkipClusterSend(channelID string) {
|
||||
ps.Store.Channel().InvalidateCacheForChannelMembersNotifyProps(channelID)
|
||||
}
|
||||
|
||||
func (ps *PlatformService) invalidateCacheForChannelByNameSkipClusterSend(teamID, name string) {
|
||||
if teamID == "" {
|
||||
teamID = "dm"
|
||||
}
|
||||
|
||||
ps.Store.Channel().InvalidateChannelByName(teamID, name)
|
||||
}
|
||||
|
||||
func (ps *PlatformService) InvalidateCacheForUserSkipClusterSend(userID string) {
|
||||
ps.Store.Channel().InvalidateAllChannelMembersForUser(userID)
|
||||
ps.invalidateWebConnSessionCacheForUser(userID)
|
||||
}
|
||||
|
||||
func (ps *PlatformService) invalidateWebConnSessionCacheForUser(userID string) {
|
||||
hub := ps.GetHubForUserId(userID)
|
||||
if hub != nil {
|
||||
|
||||
@@ -165,24 +165,12 @@ func (ps *PlatformService) HubUnregister(webConn *WebConn) {
|
||||
|
||||
func (ps *PlatformService) InvalidateCacheForChannel(channel *model.Channel) {
|
||||
ps.Store.Channel().InvalidateChannel(channel.Id)
|
||||
ps.invalidateCacheForChannelByNameSkipClusterSend(channel.TeamId, channel.Name)
|
||||
|
||||
if ps.clusterIFace != nil {
|
||||
nameMsg := &model.ClusterMessage{
|
||||
Event: model.ClusterEventInvalidateCacheForChannelByName,
|
||||
SendType: model.ClusterSendBestEffort,
|
||||
Props: make(map[string]string),
|
||||
}
|
||||
|
||||
nameMsg.Props["name"] = channel.Name
|
||||
if channel.TeamId == "" {
|
||||
nameMsg.Props["id"] = "dm"
|
||||
} else {
|
||||
nameMsg.Props["id"] = channel.TeamId
|
||||
}
|
||||
|
||||
ps.clusterIFace.SendClusterMessage(nameMsg)
|
||||
teamID := channel.TeamId
|
||||
if teamID == "" {
|
||||
teamID = "dm"
|
||||
}
|
||||
|
||||
ps.Store.Channel().InvalidateChannelByName(teamID, channel.Name)
|
||||
}
|
||||
|
||||
func (ps *PlatformService) InvalidateCacheForChannelMembers(channelID string) {
|
||||
@@ -192,16 +180,7 @@ func (ps *PlatformService) InvalidateCacheForChannelMembers(channelID string) {
|
||||
}
|
||||
|
||||
func (ps *PlatformService) InvalidateCacheForChannelMembersNotifyProps(channelID string) {
|
||||
ps.invalidateCacheForChannelMembersNotifyPropsSkipClusterSend(channelID)
|
||||
|
||||
if ps.clusterIFace != nil {
|
||||
msg := &model.ClusterMessage{
|
||||
Event: model.ClusterEventInvalidateCacheForChannelMembersNotifyProps,
|
||||
SendType: model.ClusterSendBestEffort,
|
||||
Data: []byte(channelID),
|
||||
}
|
||||
ps.clusterIFace.SendClusterMessage(msg)
|
||||
}
|
||||
ps.Store.Channel().InvalidateCacheForChannelMembersNotifyProps(channelID)
|
||||
}
|
||||
|
||||
func (ps *PlatformService) InvalidateCacheForChannelPosts(channelID string) {
|
||||
@@ -210,19 +189,11 @@ func (ps *PlatformService) InvalidateCacheForChannelPosts(channelID string) {
|
||||
}
|
||||
|
||||
func (ps *PlatformService) InvalidateCacheForUser(userID string) {
|
||||
ps.InvalidateCacheForUserSkipClusterSend(userID)
|
||||
ps.Store.Channel().InvalidateAllChannelMembersForUser(userID)
|
||||
ps.invalidateWebConnSessionCacheForUser(userID)
|
||||
|
||||
ps.Store.User().InvalidateProfilesInChannelCacheByUser(userID)
|
||||
ps.Store.User().InvalidateProfileCacheForUser(userID)
|
||||
|
||||
if ps.clusterIFace != nil {
|
||||
msg := &model.ClusterMessage{
|
||||
Event: model.ClusterEventInvalidateCacheForUser,
|
||||
SendType: model.ClusterSendBestEffort,
|
||||
Data: []byte(userID),
|
||||
}
|
||||
ps.clusterIFace.SendClusterMessage(msg)
|
||||
}
|
||||
}
|
||||
|
||||
func (ps *PlatformService) InvalidateCacheForUserTeams(userID string) {
|
||||
|
||||
@@ -1791,7 +1791,7 @@ func TestHookPreferencesHaveChanged(t *testing.T) {
|
||||
|
||||
require.Nil(t, appErr)
|
||||
assert.Equal(t, "test_value_third", preference.Value)
|
||||
}, 1*time.Second, 10*time.Millisecond)
|
||||
}, 5*time.Second, 100*time.Millisecond)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1854,11 +1854,12 @@ func TestChannelHasBeenCreated(t *testing.T) {
|
||||
posts, appErr := th.App.GetPosts(channel.Id, 0, 1)
|
||||
|
||||
require.Nil(t, appErr)
|
||||
assert.True(t, len(posts.Order) > 0)
|
||||
|
||||
post := posts.Posts[posts.Order[0]]
|
||||
assert.Equal(t, channel.Id, post.ChannelId)
|
||||
assert.Equal(t, "ChannelHasBeenCreated has been called for "+channel.Id, post.Message)
|
||||
}, 1*time.Second, 10*time.Millisecond)
|
||||
}, 5*time.Second, 100*time.Millisecond)
|
||||
})
|
||||
|
||||
t.Run("should call hook when a DM is created", func(t *testing.T) {
|
||||
@@ -1879,11 +1880,11 @@ func TestChannelHasBeenCreated(t *testing.T) {
|
||||
posts, appErr := th.App.GetPosts(channel.Id, 0, 1)
|
||||
|
||||
require.Nil(t, appErr)
|
||||
|
||||
assert.True(t, len(posts.Order) > 0)
|
||||
post := posts.Posts[posts.Order[0]]
|
||||
assert.Equal(t, channel.Id, post.ChannelId)
|
||||
assert.Equal(t, "ChannelHasBeenCreated has been called for "+channel.Id, post.Message)
|
||||
}, 1*time.Second, 10*time.Millisecond)
|
||||
}, 5*time.Second, 100*time.Millisecond)
|
||||
})
|
||||
|
||||
t.Run("should call hook when a GM is created", func(t *testing.T) {
|
||||
@@ -1905,11 +1906,11 @@ func TestChannelHasBeenCreated(t *testing.T) {
|
||||
posts, appErr := th.App.GetPosts(channel.Id, 0, 1)
|
||||
|
||||
require.Nil(t, appErr)
|
||||
|
||||
assert.True(t, len(posts.Order) > 0)
|
||||
post := posts.Posts[posts.Order[0]]
|
||||
assert.Equal(t, channel.Id, post.ChannelId)
|
||||
assert.Equal(t, "ChannelHasBeenCreated has been called for "+channel.Id, post.Message)
|
||||
}, 1*time.Second, 10*time.Millisecond)
|
||||
}, 5*time.Second, 100*time.Millisecond)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1987,9 +1988,9 @@ func TestUserHasJoinedChannel(t *testing.T) {
|
||||
posts, appErr := th.App.GetPosts(channel.Id, 0, 1)
|
||||
|
||||
require.Nil(t, appErr)
|
||||
|
||||
assert.True(t, len(posts.Order) > 0)
|
||||
assert.Equal(t, fmt.Sprintf("Test: User %s joined %s", user2.Id, channel.Id), posts.Posts[posts.Order[0]].Message)
|
||||
}, 1*time.Second, 10*time.Millisecond)
|
||||
}, 5*time.Second, 100*time.Millisecond)
|
||||
})
|
||||
|
||||
t.Run("should call hook when a user is added to an existing channel", func(t *testing.T) {
|
||||
@@ -2023,7 +2024,6 @@ func TestUserHasJoinedChannel(t *testing.T) {
|
||||
// Typically, the post we're looking for will be the latest, but there's a race between the plugin and
|
||||
// "User has joined the channel" post which means the plugin post may not the the latest one
|
||||
posts, appErr := th.App.GetPosts(channel.Id, 0, 10)
|
||||
|
||||
require.Nil(t, appErr)
|
||||
|
||||
for _, postId := range posts.Order {
|
||||
@@ -2035,7 +2035,7 @@ func TestUserHasJoinedChannel(t *testing.T) {
|
||||
}
|
||||
|
||||
return false
|
||||
}, 1*time.Second, 10*time.Millisecond)
|
||||
}, 5*time.Second, 100*time.Millisecond)
|
||||
})
|
||||
|
||||
t.Run("should not call hook when a regular channel is created", func(t *testing.T) {
|
||||
|
||||
@@ -286,7 +286,8 @@ func TestUpdateIncomingWebhook(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCreateWebhookPost(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
testCluster := &testlib.FakeClusterInterface{}
|
||||
th := SetupWithClusterMock(t, testCluster).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableIncomingWebhooks = true })
|
||||
@@ -365,20 +366,18 @@ Date: Thu Mar 1 19:46:48 2018 +0300
|
||||
assert.Equal(t, expectedText, post.Message)
|
||||
|
||||
t.Run("should set webhook creator status to online", func(t *testing.T) {
|
||||
testCluster := &testlib.FakeClusterInterface{}
|
||||
th.Server.Platform().SetCluster(testCluster)
|
||||
defer th.Server.Platform().SetCluster(nil)
|
||||
|
||||
testCluster.ClearMessages()
|
||||
_, appErr := th.App.CreateWebhookPost(th.Context, hook.UserId, th.BasicChannel, "text", "", "", "", model.StringInterface{}, model.PostTypeDefault, "")
|
||||
require.Nil(t, appErr)
|
||||
|
||||
msgs := testCluster.GetMessages()
|
||||
// The first message is ClusterEventInvalidateCacheForChannelByName so we skip it
|
||||
ev, err1 := model.WebSocketEventFromJSON(bytes.NewReader(msgs[1].Data))
|
||||
require.NoError(t, err1)
|
||||
require.Equal(t, model.WebsocketEventPosted, ev.EventType())
|
||||
assert.Equal(t, false, ev.GetData()["set_online"])
|
||||
msgs := testCluster.SelectMessages(func(msg *model.ClusterMessage) bool {
|
||||
event, err := model.WebSocketEventFromJSON(bytes.NewReader(msg.Data))
|
||||
return err == nil && event.EventType() == model.WebsocketEventPosted
|
||||
})
|
||||
require.Len(t, msgs, 1)
|
||||
// We know there will be no error from the filter condition.
|
||||
event, _ := model.WebSocketEventFromJSON(bytes.NewReader(msgs[0].Data))
|
||||
assert.Equal(t, false, event.GetData()["set_online"])
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user