From f3c7510c704450f37e10ae5691d80c166ae72d84 Mon Sep 17 00:00:00 2001 From: Agniva De Sarker Date: Thu, 15 Feb 2024 19:20:48 +0530 Subject: [PATCH] MM-56878: Remove unused store method (#26230) IsUserInChannelUseCache wasn't being used anywhere. https://mattermost.atlassian.net/browse/MM-56878 ```release-note NONE ``` --- .../opentracinglayer/opentracinglayer.go | 13 -------- .../channels/store/retrylayer/retrylayer.go | 6 ---- .../channels/store/sqlstore/channel_store.go | 30 ------------------- server/channels/store/store.go | 1 - .../channels/store/storetest/channel_store.go | 19 ------------ .../store/storetest/mocks/ChannelStore.go | 14 --------- .../channels/store/timerlayer/timerlayer.go | 16 ---------- 7 files changed, 99 deletions(-) diff --git a/server/channels/store/opentracinglayer/opentracinglayer.go b/server/channels/store/opentracinglayer/opentracinglayer.go index 5883ec90d5..578d1df16d 100644 --- a/server/channels/store/opentracinglayer/opentracinglayer.go +++ b/server/channels/store/opentracinglayer/opentracinglayer.go @@ -2059,19 +2059,6 @@ func (s *OpenTracingLayerChannelStore) InvalidatePinnedPostCount(channelID strin } -func (s *OpenTracingLayerChannelStore) IsUserInChannelUseCache(userID string, channelID string) bool { - origCtx := s.Root.Store.Context() - span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.IsUserInChannelUseCache") - s.Root.Store.SetContext(newCtx) - defer func() { - s.Root.Store.SetContext(origCtx) - }() - - defer span.Finish() - result := s.ChannelStore.IsUserInChannelUseCache(userID, channelID) - return result -} - func (s *OpenTracingLayerChannelStore) MigrateChannelMembers(fromChannelID string, fromUserID string) (map[string]string, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.MigrateChannelMembers") diff --git a/server/channels/store/retrylayer/retrylayer.go b/server/channels/store/retrylayer/retrylayer.go index d10a5c02ae..a710fa58ca 100644 --- a/server/channels/store/retrylayer/retrylayer.go +++ b/server/channels/store/retrylayer/retrylayer.go @@ -2252,12 +2252,6 @@ func (s *RetryLayerChannelStore) InvalidatePinnedPostCount(channelID string) { } -func (s *RetryLayerChannelStore) IsUserInChannelUseCache(userID string, channelID string) bool { - - return s.ChannelStore.IsUserInChannelUseCache(userID, channelID) - -} - func (s *RetryLayerChannelStore) MigrateChannelMembers(fromChannelID string, fromUserID string) (map[string]string, error) { tries := 0 diff --git a/server/channels/store/sqlstore/channel_store.go b/server/channels/store/sqlstore/channel_store.go index 32b30cf51c..048c87e292 100644 --- a/server/channels/store/sqlstore/channel_store.go +++ b/server/channels/store/sqlstore/channel_store.go @@ -17,7 +17,6 @@ import ( "github.com/pkg/errors" "github.com/mattermost/mattermost/server/public/model" - "github.com/mattermost/mattermost/server/public/shared/mlog" "github.com/mattermost/mattermost/server/public/shared/request" "github.com/mattermost/mattermost/server/v8/channels/store" "github.com/mattermost/mattermost/server/v8/einterfaces" @@ -2164,35 +2163,6 @@ func (s SqlChannelStore) InvalidateAllChannelMembersForUser(userId string) { } } -func (s SqlChannelStore) IsUserInChannelUseCache(userId string, channelId string) bool { - var ids map[string]string - if err := allChannelMembersForUserCache.Get(userId, &ids); err == nil { - if s.metrics != nil { - s.metrics.IncrementMemCacheHitCounter("All Channel Members for User") - } - if _, ok := ids[channelId]; ok { - return true - } - return false - } - - if s.metrics != nil { - s.metrics.IncrementMemCacheMissCounter("All Channel Members for User") - } - - ids, err := s.GetAllChannelMembersForUser(userId, true, false) - if err != nil { - mlog.Error("Error getting all channel members for user", mlog.Err(err)) - return false - } - - if _, ok := ids[channelId]; ok { - return true - } - - return false -} - func (s SqlChannelStore) GetMemberForPost(postId string, userId string, includeArchivedChannels bool) (*model.ChannelMember, error) { var dbMember channelMemberWithSchemeRoles query := ` diff --git a/server/channels/store/store.go b/server/channels/store/store.go index 11cdddc0d9..4b69bfe2ab 100644 --- a/server/channels/store/store.go +++ b/server/channels/store/store.go @@ -232,7 +232,6 @@ type ChannelStore interface { GetAllChannelMembersForUser(userID string, allowFromCache bool, includeDeleted bool) (map[string]string, error) GetChannelsMemberCount(channelIDs []string) (map[string]int64, error) InvalidateAllChannelMembersForUser(userID string) - IsUserInChannelUseCache(userID string, channelID string) bool GetAllChannelMembersNotifyPropsForChannel(channelID string, allowFromCache bool) (map[string]model.StringMap, error) InvalidateCacheForChannelMembersNotifyProps(channelID string) GetMemberForPost(postID string, userID string, includeArchivedChannels bool) (*model.ChannelMember, error) diff --git a/server/channels/store/storetest/channel_store.go b/server/channels/store/storetest/channel_store.go index d0477baca9..ba1c2059be 100644 --- a/server/channels/store/storetest/channel_store.go +++ b/server/channels/store/storetest/channel_store.go @@ -3737,25 +3737,6 @@ func testChannelStoreGetChannels(t *testing.T, rctx request.CTX, ss store.Store) require.Equal(t, o1.Id, list[0].Id, "missing channel") require.Equal(t, o3.Id, list[1].Id, "missing channel") - require.True( - t, - ss.Channel().IsUserInChannelUseCache(m1.UserId, o1.Id), - "missing channel") - require.True( - t, - ss.Channel().IsUserInChannelUseCache(m1.UserId, o2.Id), - "missing channel") - - require.False( - t, - ss.Channel().IsUserInChannelUseCache(m1.UserId, "blahblah"), - "missing channel") - - require.False( - t, - ss.Channel().IsUserInChannelUseCache("blahblah", "blahblah"), - "missing channel") - ss.Channel().InvalidateAllChannelMembersForUser(m1.UserId) } diff --git a/server/channels/store/storetest/mocks/ChannelStore.go b/server/channels/store/storetest/mocks/ChannelStore.go index 18ec1542fc..05f043a16a 100644 --- a/server/channels/store/storetest/mocks/ChannelStore.go +++ b/server/channels/store/storetest/mocks/ChannelStore.go @@ -1903,20 +1903,6 @@ func (_m *ChannelStore) InvalidatePinnedPostCount(channelID string) { _m.Called(channelID) } -// IsUserInChannelUseCache provides a mock function with given fields: userID, channelID -func (_m *ChannelStore) IsUserInChannelUseCache(userID string, channelID string) bool { - ret := _m.Called(userID, channelID) - - var r0 bool - if rf, ok := ret.Get(0).(func(string, string) bool); ok { - r0 = rf(userID, channelID) - } else { - r0 = ret.Get(0).(bool) - } - - return r0 -} - // MigrateChannelMembers provides a mock function with given fields: fromChannelID, fromUserID func (_m *ChannelStore) MigrateChannelMembers(fromChannelID string, fromUserID string) (map[string]string, error) { ret := _m.Called(fromChannelID, fromUserID) diff --git a/server/channels/store/timerlayer/timerlayer.go b/server/channels/store/timerlayer/timerlayer.go index 000181784f..49c74ca932 100644 --- a/server/channels/store/timerlayer/timerlayer.go +++ b/server/channels/store/timerlayer/timerlayer.go @@ -1918,22 +1918,6 @@ func (s *TimerLayerChannelStore) InvalidatePinnedPostCount(channelID string) { } } -func (s *TimerLayerChannelStore) IsUserInChannelUseCache(userID string, channelID string) bool { - start := time.Now() - - result := s.ChannelStore.IsUserInChannelUseCache(userID, channelID) - - elapsed := float64(time.Since(start)) / float64(time.Second) - if s.Root.Metrics != nil { - success := "false" - if true { - success = "true" - } - s.Root.Metrics.ObserveStoreMethodDuration("ChannelStore.IsUserInChannelUseCache", success, elapsed) - } - return result -} - func (s *TimerLayerChannelStore) MigrateChannelMembers(fromChannelID string, fromUserID string) (map[string]string, error) { start := time.Now()