MM-48181: Invalidate cache to reflect permissions changes from a team scheme. (#21735)

* MM-48181: Bust the allChannelMembersForUserCache when assigning a team scheme.

* MM-48181: Tests cache fix.
Этот коммит содержится в:
Martin Kraft
2022-11-28 11:18:17 -05:00
коммит произвёл GitHub
родитель 98a14c8c55
Коммит 3e7a8d8426
8 изменённых файлов: 85 добавлений и 0 удалений

Просмотреть файл

@@ -696,6 +696,19 @@ func (s *OpenTracingLayerChannelStore) ClearCaches() {
}
func (s *OpenTracingLayerChannelStore) ClearMembersForUserCache() {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.ClearMembersForUserCache")
s.Root.Store.SetContext(newCtx)
defer func() {
s.Root.Store.SetContext(origCtx)
}()
defer span.Finish()
s.ChannelStore.ClearMembersForUserCache()
}
func (s *OpenTracingLayerChannelStore) ClearSidebarOnTeamLeave(userID string, teamID string) error {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.ClearSidebarOnTeamLeave")

Просмотреть файл

@@ -750,6 +750,12 @@ func (s *RetryLayerChannelStore) ClearCaches() {
}
func (s *RetryLayerChannelStore) ClearMembersForUserCache() {
s.ChannelStore.ClearMembersForUserCache()
}
func (s *RetryLayerChannelStore) ClearSidebarOnTeamLeave(userID string, teamID string) error {
tries := 0

Просмотреть файл

@@ -451,6 +451,10 @@ var channelByNameCache = cache.NewLRU(cache.LRUOptions{
Size: model.ChannelCacheSize,
})
func (s SqlChannelStore) ClearMembersForUserCache() {
allChannelMembersForUserCache.Purge()
}
func (s SqlChannelStore) ClearCaches() {
allChannelMembersForUserCache.Purge()
allChannelMembersNotifyPropsForChannelCache.Purge()

Просмотреть файл

@@ -267,6 +267,7 @@ type ChannelStore interface {
AnalyticsDeletedTypeCount(teamID string, channelType model.ChannelType) (int64, error)
GetChannelUnread(channelID, userID string) (*model.ChannelUnread, error)
ClearCaches()
ClearMembersForUserCache()
GetChannelsByScheme(schemeID string, offset int, limit int) (model.ChannelList, error)
MigrateChannelMembers(fromChannelID string, fromUserID string) (map[string]string, error)
ResetAllChannelSchemes() error

Просмотреть файл

@@ -150,6 +150,11 @@ func (_m *ChannelStore) ClearCaches() {
_m.Called()
}
// ClearMembersForUserCache provides a mock function with given fields:
func (_m *ChannelStore) ClearMembersForUserCache() {
_m.Called()
}
// ClearSidebarOnTeamLeave provides a mock function with given fields: userID, teamID
func (_m *ChannelStore) ClearSidebarOnTeamLeave(userID string, teamID string) error {
ret := _m.Called(userID, teamID)

Просмотреть файл

@@ -669,6 +669,21 @@ func (s *TimerLayerChannelStore) ClearCaches() {
}
}
func (s *TimerLayerChannelStore) ClearMembersForUserCache() {
start := time.Now()
s.ChannelStore.ClearMembersForUserCache()
elapsed := float64(time.Since(start)) / float64(time.Second)
if s.Root.Metrics != nil {
success := "false"
if true {
success = "true"
}
s.Root.Metrics.ObserveStoreMethodDuration("ChannelStore.ClearMembersForUserCache", success, elapsed)
}
}
func (s *TimerLayerChannelStore) ClearSidebarOnTeamLeave(userID string, teamID string) error {
start := time.Now()