From 464c290e5061aa606f145e1fda16a28e5a4bd611 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Espino?= Date: Wed, 8 Jan 2020 11:31:10 +0100 Subject: [PATCH] Removing certain unneded cluster invalidation messages (#13549) * Removing certain unneded cluster invalidation messages * Fixing typo * Removing channges included in other PR * Adding doc string to RegisterAllClusterMessageHandlers method * fixing typos Co-authored-by: mattermod --- app/cluster_handlers.go | 16 +-- app/web_hub.go | 37 +------ store/localcachelayer/user_layer.go | 2 +- store/localcachelayer/user_layer_test.go | 4 +- store/sqlstore/user_store.go | 2 +- store/store.go | 2 +- store/storetest/mocks/UserStore.go | 4 +- store/storetest/user_store.go | 2 +- store/timer_layer.go | 130 +++++++++++++++++++++-- 9 files changed, 138 insertions(+), 61 deletions(-) diff --git a/app/cluster_handlers.go b/app/cluster_handlers.go index ef8199768f..783096d859 100644 --- a/app/cluster_handlers.go +++ b/app/cluster_handlers.go @@ -9,12 +9,15 @@ import ( "github.com/mattermost/mattermost-server/v5/model" ) +// RegisterAllClusterMessageHandlers registers the cluster message handlers that are handled by the App layer. +// +// The cluster event handlers are spread across this function and +// NewLocalCacheLayer. Be careful to not have duplicated handlers here and +// there. func (a *App) RegisterAllClusterMessageHandlers() { a.Cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_PUBLISH, a.ClusterPublishHandler) a.Cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_UPDATE_STATUS, a.ClusterUpdateStatusHandler) a.Cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_ALL_CACHES, a.ClusterInvalidateAllCachesHandler) - a.Cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_WEBHOOK, a.ClusterInvalidateCacheForWebhookHandler) - a.Cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_POSTS, a.ClusterInvalidateCacheForChannelPostsHandler) a.Cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_MEMBERS_NOTIFY_PROPS, a.ClusterInvalidateCacheForChannelMembersNotifyPropHandler) a.Cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_MEMBERS, a.ClusterInvalidateCacheForChannelMembersHandler) a.Cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_BY_NAME, a.ClusterInvalidateCacheForChannelByNameHandler) @@ -25,7 +28,6 @@ func (a *App) RegisterAllClusterMessageHandlers() { a.Cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_INSTALL_PLUGIN, a.ClusterInstallPluginHandler) a.Cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_REMOVE_PLUGIN, a.ClusterRemovePluginHandler) a.Cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_BUSY_STATE_CHANGED, a.ClusterBusyStateChgHandler) - } func (a *App) ClusterPublishHandler(msg *model.ClusterMessage) { @@ -42,14 +44,6 @@ func (a *App) ClusterInvalidateAllCachesHandler(msg *model.ClusterMessage) { a.InvalidateAllCachesSkipSend() } -func (a *App) ClusterInvalidateCacheForWebhookHandler(msg *model.ClusterMessage) { - a.InvalidateCacheForWebhookSkipClusterSend(msg.Data) -} - -func (a *App) ClusterInvalidateCacheForChannelPostsHandler(msg *model.ClusterMessage) { - a.InvalidateCacheForChannelPostsSkipClusterSend(msg.Data) -} - func (a *App) ClusterInvalidateCacheForChannelMembersNotifyPropHandler(msg *model.ClusterMessage) { a.InvalidateCacheForChannelMembersNotifyPropsSkipClusterSend(msg.Data) } diff --git a/app/web_hub.go b/app/web_hub.go index 31161b0a0b..82af197196 100644 --- a/app/web_hub.go +++ b/app/web_hub.go @@ -225,6 +225,8 @@ func (a *App) InvalidateCacheForChannel(channel *model.Channel) { func (a *App) InvalidateCacheForChannelMembers(channelId string) { a.InvalidateCacheForChannelMembersSkipClusterSend(channelId) + a.Srv.Store.Channel().InvalidateMemberCount(channelId) + a.Srv.Store.Channel().InvalidateGuestCount(channelId) if a.Cluster != nil { msg := &model.ClusterMessage{ @@ -238,8 +240,6 @@ func (a *App) InvalidateCacheForChannelMembers(channelId string) { func (a *App) InvalidateCacheForChannelMembersSkipClusterSend(channelId string) { a.Srv.Store.User().InvalidateProfilesInChannelCache(channelId) - a.Srv.Store.Channel().InvalidateMemberCount(channelId) - a.Srv.Store.Channel().InvalidateGuestCount(channelId) } func (a *App) InvalidateCacheForChannelMembersNotifyProps(channelId string) { @@ -268,21 +268,8 @@ func (a *App) InvalidateCacheForChannelByNameSkipClusterSend(teamId, name string } func (a *App) InvalidateCacheForChannelPosts(channelId string) { - a.InvalidateCacheForChannelPostsSkipClusterSend(channelId) - - if a.Cluster != nil { - msg := &model.ClusterMessage{ - Event: model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_POSTS, - SendType: model.CLUSTER_SEND_BEST_EFFORT, - Data: channelId, - } - a.Cluster.SendClusterMessage(msg) - } -} - -func (a *App) InvalidateCacheForChannelPostsSkipClusterSend(channelId string) { - a.Srv.Store.Post().InvalidateLastPostTimeCache(channelId) a.Srv.Store.Channel().InvalidatePinnedPostCount(channelId) + a.Srv.Store.Post().InvalidateLastPostTimeCache(channelId) } func (a *App) InvalidateCacheForUser(userId string) { @@ -300,6 +287,7 @@ func (a *App) InvalidateCacheForUser(userId string) { func (a *App) InvalidateCacheForUserTeams(userId string) { a.InvalidateCacheForUserTeamsSkipClusterSend(userId) + a.Srv.Store.Team().InvalidateAllTeamIdsForUser(userId) if a.Cluster != nil { msg := &model.ClusterMessage{ @@ -314,7 +302,7 @@ func (a *App) InvalidateCacheForUserTeams(userId string) { func (a *App) InvalidateCacheForUserSkipClusterSend(userId string) { a.Srv.Store.Channel().InvalidateAllChannelMembersForUser(userId) a.Srv.Store.User().InvalidateProfilesInChannelCacheByUser(userId) - a.Srv.Store.User().InvalidatProfileCacheForUser(userId) + a.Srv.Store.User().InvalidateProfileCacheForUser(userId) hub := a.GetHubForUserId(userId) if hub != nil { @@ -323,8 +311,6 @@ func (a *App) InvalidateCacheForUserSkipClusterSend(userId string) { } func (a *App) InvalidateCacheForUserTeamsSkipClusterSend(userId string) { - a.Srv.Store.Team().InvalidateAllTeamIdsForUser(userId) - hub := a.GetHubForUserId(userId) if hub != nil { hub.InvalidateUser(userId) @@ -332,19 +318,6 @@ func (a *App) InvalidateCacheForUserTeamsSkipClusterSend(userId string) { } func (a *App) InvalidateCacheForWebhook(webhookId string) { - a.InvalidateCacheForWebhookSkipClusterSend(webhookId) - - if a.Cluster != nil { - msg := &model.ClusterMessage{ - Event: model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_WEBHOOK, - SendType: model.CLUSTER_SEND_BEST_EFFORT, - Data: webhookId, - } - a.Cluster.SendClusterMessage(msg) - } -} - -func (a *App) InvalidateCacheForWebhookSkipClusterSend(webhookId string) { a.Srv.Store.Webhook().InvalidateWebhookCache(webhookId) } diff --git a/store/localcachelayer/user_layer.go b/store/localcachelayer/user_layer.go index 102df7e342..b55d1065cd 100644 --- a/store/localcachelayer/user_layer.go +++ b/store/localcachelayer/user_layer.go @@ -31,7 +31,7 @@ func (s LocalCacheUserStore) ClearCaches() { } } -func (s LocalCacheUserStore) InvalidatProfileCacheForUser(userId string) { +func (s LocalCacheUserStore) InvalidateProfileCacheForUser(userId string) { s.rootStore.doInvalidateCacheCluster(s.rootStore.userProfileByIdsCache, userId) if s.rootStore.metrics != nil { diff --git a/store/localcachelayer/user_layer_test.go b/store/localcachelayer/user_layer_test.go index 9b43be64f2..baebf5ee75 100644 --- a/store/localcachelayer/user_layer_test.go +++ b/store/localcachelayer/user_layer_test.go @@ -58,7 +58,7 @@ func TestUserStoreGetProfileByIdsCache(t *testing.T) { assert.Equal(t, fakeUser, gotUser) mockStore.User().(*mocks.UserStore).AssertNumberOfCalls(t, "GetProfileByIds", 1) - cachedStore.User().InvalidatProfileCacheForUser("123") + cachedStore.User().InvalidateProfileCacheForUser("123") _, _ = cachedStore.User().GetProfileByIds(fakeUserIds, &store.UserGetByIdsOpts{}, true) mockStore.User().(*mocks.UserStore).AssertNumberOfCalls(t, "GetProfileByIds", 2) @@ -91,7 +91,7 @@ func TestUserStoreGetCache(t *testing.T) { assert.Equal(t, fakeUser, gotUser) mockStore.User().(*mocks.UserStore).AssertNumberOfCalls(t, "Get", 1) - cachedStore.User().InvalidatProfileCacheForUser("123") + cachedStore.User().InvalidateProfileCacheForUser("123") _, _ = cachedStore.User().Get(fakeUserId) mockStore.User().(*mocks.UserStore).AssertNumberOfCalls(t, "Get", 2) diff --git a/store/sqlstore/user_store.go b/store/sqlstore/user_store.go index 9e11f73754..445eb35b29 100644 --- a/store/sqlstore/user_store.go +++ b/store/sqlstore/user_store.go @@ -51,7 +51,7 @@ func (us SqlUserStore) ClearCaches() { } } -func (us SqlUserStore) InvalidatProfileCacheForUser(userId string) {} +func (us SqlUserStore) InvalidateProfileCacheForUser(userId string) {} func NewSqlUserStore(sqlStore SqlStore, metrics einterfaces.MetricsInterface) store.UserStore { us := &SqlUserStore{ diff --git a/store/store.go b/store/store.go index 3c8b452c57..92c96779ea 100644 --- a/store/store.go +++ b/store/store.go @@ -261,7 +261,7 @@ type UserStore interface { GetProfiles(options *model.UserGetOptions) ([]*model.User, *model.AppError) GetProfileByIds(userIds []string, options *UserGetByIdsOpts, allowFromCache bool) ([]*model.User, *model.AppError) GetProfileByGroupChannelIdsForUser(userId string, channelIds []string) (map[string][]*model.User, *model.AppError) - InvalidatProfileCacheForUser(userId string) + InvalidateProfileCacheForUser(userId string) GetByEmail(email string) (*model.User, *model.AppError) GetByAuth(authData *string, authService string) (*model.User, *model.AppError) GetAllUsingAuthService(authService string) ([]*model.User, *model.AppError) diff --git a/store/storetest/mocks/UserStore.go b/store/storetest/mocks/UserStore.go index f8ede26c65..3c3cd98a25 100644 --- a/store/storetest/mocks/UserStore.go +++ b/store/storetest/mocks/UserStore.go @@ -928,8 +928,8 @@ func (_m *UserStore) InferSystemInstallDate() (int64, *model.AppError) { return r0, r1 } -// InvalidatProfileCacheForUser provides a mock function with given fields: userId -func (_m *UserStore) InvalidatProfileCacheForUser(userId string) { +// InvalidateProfileCacheForUser provides a mock function with given fields: userId +func (_m *UserStore) InvalidateProfileCacheForUser(userId string) { _m.Called(userId) } diff --git a/store/storetest/user_store.go b/store/storetest/user_store.go index dbb5fea27e..7522eebfec 100644 --- a/store/storetest/user_store.go +++ b/store/storetest/user_store.go @@ -4949,7 +4949,7 @@ func testUserStoreResetLastPictureUpdate(t *testing.T, ss store.Store) { err = ss.User().ResetLastPictureUpdate(u1.Id) require.Nil(t, err) - ss.User().InvalidatProfileCacheForUser(u1.Id) + ss.User().InvalidateProfileCacheForUser(u1.Id) user2, err := ss.User().Get(u1.Id) require.Nil(t, err) diff --git a/store/timer_layer.go b/store/timer_layer.go index ae007f911a..0c3cdeba89 100644 --- a/store/timer_layer.go +++ b/store/timer_layer.go @@ -552,6 +552,22 @@ func (s *TimerLayerChannelStore) ClearCaches() { return } +func (s *TimerLayerChannelStore) CountPostsAfter(channelId string, timestamp int64, userId string) (int, *model.AppError) { + start := timemodule.Now() + + resultVar0, resultVar1 := s.ChannelStore.CountPostsAfter(channelId, timestamp, userId) + + elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second) + if s.Root.Metrics != nil { + success := "false" + if resultVar1 == nil { + success = "true" + } + s.Root.Metrics.ObserveStoreMethodDuration("ChannelStore.CountPostsAfter", success, elapsed) + } + return resultVar0, resultVar1 +} + func (s *TimerLayerChannelStore) CreateDirectChannel(userId *model.User, otherUserId *model.User) (*model.Channel, *model.AppError) { start := timemodule.Now() @@ -1560,6 +1576,22 @@ func (s *TimerLayerChannelStore) SearchAllChannels(term string, opts ChannelSear return resultVar0, resultVar1, resultVar2 } +func (s *TimerLayerChannelStore) SearchArchivedInTeam(teamId string, term string, userId string) (*model.ChannelList, *model.AppError) { + start := timemodule.Now() + + resultVar0, resultVar1 := s.ChannelStore.SearchArchivedInTeam(teamId, term, userId) + + elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second) + if s.Root.Metrics != nil { + success := "false" + if resultVar1 == nil { + success = "true" + } + s.Root.Metrics.ObserveStoreMethodDuration("ChannelStore.SearchArchivedInTeam", success, elapsed) + } + return resultVar0, resultVar1 +} + func (s *TimerLayerChannelStore) SearchForUserInTeam(userId string, teamId string, term string, includeDeleted bool) (*model.ChannelList, *model.AppError) { start := timemodule.Now() @@ -1672,6 +1704,22 @@ func (s *TimerLayerChannelStore) UpdateLastViewedAt(channelIds []string, userId return resultVar0, resultVar1 } +func (s *TimerLayerChannelStore) UpdateLastViewedAtPost(unreadPost *model.Post, userID string, mentionCount int) (*model.ChannelUnreadAt, *model.AppError) { + start := timemodule.Now() + + resultVar0, resultVar1 := s.ChannelStore.UpdateLastViewedAtPost(unreadPost, userID, mentionCount) + + elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second) + if s.Root.Metrics != nil { + success := "false" + if resultVar1 == nil { + success = "true" + } + s.Root.Metrics.ObserveStoreMethodDuration("ChannelStore.UpdateLastViewedAtPost", success, elapsed) + } + return resultVar0, resultVar1 +} + func (s *TimerLayerChannelStore) UpdateMember(member *model.ChannelMember) (*model.ChannelMember, *model.AppError) { start := timemodule.Now() @@ -2733,14 +2781,13 @@ func (s *TimerLayerGroupStore) GetByName(name string) (*model.Group, *model.AppE resultVar0, resultVar1 := s.GroupStore.GetByName(name) - t := timemodule.Now() - elapsed := t.Sub(start) + elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second) if s.Root.Metrics != nil { success := "false" if resultVar1 == nil { success = "true" } - s.Root.Metrics.ObserveStoreMethodDuration("GroupStore.GetByName", success, float64(elapsed)) + s.Root.Metrics.ObserveStoreMethodDuration("GroupStore.GetByName", success, elapsed) } return resultVar0, resultVar1 } @@ -2766,14 +2813,13 @@ func (s *TimerLayerGroupStore) GetByUser(userId string) ([]*model.Group, *model. resultVar0, resultVar1 := s.GroupStore.GetByUser(userId) - t := timemodule.Now() - elapsed := t.Sub(start) + elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second) if s.Root.Metrics != nil { success := "false" if resultVar1 == nil { success = "true" } - s.Root.Metrics.ObserveStoreMethodDuration("GroupStore.GetByUser", success, float64(elapsed)) + s.Root.Metrics.ObserveStoreMethodDuration("GroupStore.GetByUser", success, elapsed) } return resultVar0, resultVar1 } @@ -2890,6 +2936,22 @@ func (s *TimerLayerGroupStore) GetMemberUsersPage(groupID string, page int, perP return resultVar0, resultVar1 } +func (s *TimerLayerGroupStore) PermanentDeleteMembersByUser(userId string) *model.AppError { + start := timemodule.Now() + + resultVar0 := s.GroupStore.PermanentDeleteMembersByUser(userId) + + elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second) + if s.Root.Metrics != nil { + success := "false" + if resultVar0 == nil { + success = "true" + } + s.Root.Metrics.ObserveStoreMethodDuration("GroupStore.PermanentDeleteMembersByUser", success, elapsed) + } + return resultVar0 +} + func (s *TimerLayerGroupStore) TeamMembersMinusGroupMembers(teamID string, groupIDs []string, page int, perPage int) ([]*model.UserWithGroups, *model.AppError) { start := timemodule.Now() @@ -3674,6 +3736,22 @@ func (s *TimerLayerPluginStore) SaveOrUpdate(keyVal *model.PluginKeyValue) (*mod return resultVar0, resultVar1 } +func (s *TimerLayerPluginStore) SetWithOptions(pluginId string, key string, value []byte, options model.PluginKVSetOptions) (bool, *model.AppError) { + start := timemodule.Now() + + resultVar0, resultVar1 := s.PluginStore.SetWithOptions(pluginId, key, value, options) + + elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second) + if s.Root.Metrics != nil { + success := "false" + if resultVar1 == nil { + success = "true" + } + s.Root.Metrics.ObserveStoreMethodDuration("PluginStore.SetWithOptions", success, elapsed) + } + return resultVar0, resultVar1 +} + func (s *TimerLayerPostStore) AnalyticsPostCount(teamId string, mustHaveFile bool, mustHaveHashtag bool) (int64, *model.AppError) { start := timemodule.Now() @@ -5706,6 +5784,22 @@ func (s *TimerLayerTeamStore) SearchAll(term string) ([]*model.Team, *model.AppE return resultVar0, resultVar1 } +func (s *TimerLayerTeamStore) SearchAllPaged(term string, page int, perPage int) ([]*model.Team, int64, *model.AppError) { + start := timemodule.Now() + + resultVar0, resultVar1, resultVar2 := s.TeamStore.SearchAllPaged(term, page, perPage) + + elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second) + if s.Root.Metrics != nil { + success := "false" + if resultVar2 == nil { + success = "true" + } + s.Root.Metrics.ObserveStoreMethodDuration("TeamStore.SearchAllPaged", success, elapsed) + } + return resultVar0, resultVar1, resultVar2 +} + func (s *TimerLayerTeamStore) SearchOpen(term string) ([]*model.Team, *model.AppError) { start := timemodule.Now() @@ -6026,6 +6120,22 @@ func (s *TimerLayerUserStore) Count(options model.UserCountOptions) (int64, *mod return resultVar0, resultVar1 } +func (s *TimerLayerUserStore) DeactivateGuests() ([]string, *model.AppError) { + start := timemodule.Now() + + resultVar0, resultVar1 := s.UserStore.DeactivateGuests() + + elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second) + if s.Root.Metrics != nil { + success := "false" + if resultVar1 == nil { + success = "true" + } + s.Root.Metrics.ObserveStoreMethodDuration("UserStore.DeactivateGuests", success, elapsed) + } + return resultVar0, resultVar1 +} + func (s *TimerLayerUserStore) DemoteUserToGuest(userID string) *model.AppError { start := timemodule.Now() @@ -6498,7 +6608,7 @@ func (s *TimerLayerUserStore) GetUnreadCount(userId string) (int64, *model.AppEr elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second) if s.Root.Metrics != nil { success := "false" - if true { + if resultVar1 == nil { success = "true" } s.Root.Metrics.ObserveStoreMethodDuration("UserStore.GetUnreadCount", success, elapsed) @@ -6554,10 +6664,10 @@ func (s *TimerLayerUserStore) InferSystemInstallDate() (int64, *model.AppError) return resultVar0, resultVar1 } -func (s *TimerLayerUserStore) InvalidatProfileCacheForUser(userId string) { +func (s *TimerLayerUserStore) InvalidateProfileCacheForUser(userId string) { start := timemodule.Now() - s.UserStore.InvalidatProfileCacheForUser(userId) + s.UserStore.InvalidateProfileCacheForUser(userId) elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second) if s.Root.Metrics != nil { @@ -6565,7 +6675,7 @@ func (s *TimerLayerUserStore) InvalidatProfileCacheForUser(userId string) { if true { success = "true" } - s.Root.Metrics.ObserveStoreMethodDuration("UserStore.InvalidatProfileCacheForUser", success, elapsed) + s.Root.Metrics.ObserveStoreMethodDuration("UserStore.InvalidateProfileCacheForUser", success, elapsed) } return }