mirror of
https://github.com/hanzoai/team.git
synced 2026-10-30 14:49:35 +00:00
* Fix plugin API CreateChannel read-after-write failure with read replicas LocalCacheChannelStore did not override Save, so newly created channels were never added to channelByIdCache. When a plugin called CreateChannel followed immediately by AddChannelMember, the GetChannel lookup missed the cache and fell through to GetReplica(), which on deployments with DataSourceReplicas could read from a replica that hadn't replicated the channel yet, returning "channel not found". Add a Save override to LocalCacheChannelStore that populates channelByIdCache after a successful save, following the same pattern used by LocalCacheTermsOfServiceStore.Save.
64 lines
2.0 KiB
Go
64 lines
2.0 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package localcachelayer
|
|
|
|
import (
|
|
"bytes"
|
|
|
|
"github.com/mattermost/mattermost/server/public/model"
|
|
"github.com/mattermost/mattermost/server/v8/channels/store"
|
|
)
|
|
|
|
type LocalCacheSchemeStore struct {
|
|
store.SchemeStore
|
|
rootStore *LocalCacheStore
|
|
}
|
|
|
|
func (s *LocalCacheSchemeStore) handleClusterInvalidateScheme(msg *model.ClusterMessage) {
|
|
if bytes.Equal(msg.Data, clearCacheMessageData) {
|
|
s.rootStore.schemeCache.Purge()
|
|
} else {
|
|
s.rootStore.schemeCache.Remove(string(msg.Data))
|
|
}
|
|
}
|
|
|
|
func (s LocalCacheSchemeStore) Save(scheme *model.Scheme) (*model.Scheme, error) {
|
|
if scheme.Id != "" {
|
|
defer s.rootStore.doInvalidateCacheCluster(s.rootStore.schemeCache, scheme.Id, nil)
|
|
}
|
|
return s.SchemeStore.Save(scheme)
|
|
}
|
|
|
|
func (s LocalCacheSchemeStore) Get(schemeId string) (*model.Scheme, error) {
|
|
var scheme *model.Scheme
|
|
if err := s.rootStore.doStandardReadCache(s.rootStore.schemeCache, schemeId, &scheme); err == nil {
|
|
return scheme, nil
|
|
}
|
|
|
|
scheme, err := s.SchemeStore.Get(schemeId)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
s.rootStore.doStandardAddToCache(s.rootStore.schemeCache, schemeId, scheme)
|
|
|
|
return scheme, nil
|
|
}
|
|
|
|
func (s LocalCacheSchemeStore) Delete(schemeId string) (*model.Scheme, error) {
|
|
defer s.rootStore.doInvalidateCacheCluster(s.rootStore.schemeCache, schemeId, nil)
|
|
defer s.rootStore.doClearCacheCluster(s.rootStore.roleCache)
|
|
defer s.rootStore.doClearCacheCluster(s.rootStore.rolePermissionsCache)
|
|
defer s.rootStore.doClearCacheCluster(s.rootStore.channelByIdCache)
|
|
return s.SchemeStore.Delete(schemeId)
|
|
}
|
|
|
|
func (s LocalCacheSchemeStore) PermanentDeleteAll() error {
|
|
defer s.rootStore.doClearCacheCluster(s.rootStore.schemeCache)
|
|
defer s.rootStore.doClearCacheCluster(s.rootStore.roleCache)
|
|
defer s.rootStore.doClearCacheCluster(s.rootStore.rolePermissionsCache)
|
|
defer s.rootStore.doClearCacheCluster(s.rootStore.channelByIdCache)
|
|
return s.SchemeStore.PermanentDeleteAll()
|
|
}
|