mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
* Add Scheme model and stub store. * Port ChannelStore to be Scheme aware. * Make almost all the API/APP layer work with ChannelSchemes. Only thing still hacky is UpdateChannelMemberRoles(). * Add basic SchemeStore implementation. * Migrate UpdateChannelMemberRoles properly and fix tests. * Update store tests and mocks so they work. * Include creating default roles in Scheme create store function. * Implement role deletion and start scheme deletion. * Only use non-deleted roles for authorization. * Add GetByScheme method to Team store. * Add GetChannelsByScheme. * Update store mocks. * Implement scheme deletion in the store. * Rename is valid function. * Add offset and limit to queries to fetch teams and channels by scheme. * Fix queries. * Implement scheme awareness in Team store and add a migration. * Tidy up ChannelStore mapping functions and add exhaustive unit tests. * Add all missing i18n. * Proper tests for TeamStore internal functions and fix them. * Make additional TeamMember fields nullable. * Make new ChannelMember fields nullable. * Create new nullable columns without defaults. * Make new fields in large tables nullalble. * Fix empty list of TeamMembers. * Deduplicate SQL queries. * Fix spelling. * Fix review comment. * More review fixes. * More review fixes.
114 lines
3.3 KiB
Go
114 lines
3.3 KiB
Go
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
|
// See License.txt for license information.
|
|
|
|
package store
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/mattermost/mattermost-server/einterfaces"
|
|
"github.com/mattermost/mattermost-server/model"
|
|
"github.com/mattermost/mattermost-server/utils"
|
|
)
|
|
|
|
const (
|
|
REACTION_CACHE_SIZE = 20000
|
|
REACTION_CACHE_SEC = 30 * 60
|
|
|
|
ROLE_CACHE_SIZE = 20000
|
|
ROLE_CACHE_SEC = 30 * 60
|
|
|
|
SCHEME_CACHE_SIZE = 20000
|
|
SCHEME_CACHE_SEC = 30 * 60
|
|
|
|
CLEAR_CACHE_MESSAGE_DATA = ""
|
|
)
|
|
|
|
type LocalCacheSupplier struct {
|
|
next LayeredStoreSupplier
|
|
reactionCache *utils.Cache
|
|
roleCache *utils.Cache
|
|
schemeCache *utils.Cache
|
|
metrics einterfaces.MetricsInterface
|
|
cluster einterfaces.ClusterInterface
|
|
}
|
|
|
|
func NewLocalCacheSupplier(metrics einterfaces.MetricsInterface, cluster einterfaces.ClusterInterface) *LocalCacheSupplier {
|
|
supplier := &LocalCacheSupplier{
|
|
reactionCache: utils.NewLruWithParams(REACTION_CACHE_SIZE, "Reaction", REACTION_CACHE_SEC, model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_REACTIONS),
|
|
roleCache: utils.NewLruWithParams(ROLE_CACHE_SIZE, "Role", ROLE_CACHE_SEC, model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_ROLES),
|
|
schemeCache: utils.NewLruWithParams(SCHEME_CACHE_SIZE, "Scheme", SCHEME_CACHE_SEC, model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_SCHEMES),
|
|
metrics: metrics,
|
|
cluster: cluster,
|
|
}
|
|
|
|
if cluster != nil {
|
|
cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_REACTIONS, supplier.handleClusterInvalidateReaction)
|
|
cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_ROLES, supplier.handleClusterInvalidateRole)
|
|
}
|
|
|
|
return supplier
|
|
}
|
|
|
|
func (s *LocalCacheSupplier) SetChainNext(next LayeredStoreSupplier) {
|
|
s.next = next
|
|
}
|
|
|
|
func (s *LocalCacheSupplier) Next() LayeredStoreSupplier {
|
|
return s.next
|
|
}
|
|
|
|
func (s *LocalCacheSupplier) doStandardReadCache(ctx context.Context, cache utils.ObjectCache, key string, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
|
|
if hintsContains(hints, LSH_NO_CACHE) {
|
|
if s.metrics != nil {
|
|
s.metrics.IncrementMemCacheMissCounter(cache.Name())
|
|
}
|
|
return nil
|
|
}
|
|
|
|
if cacheItem, ok := cache.Get(key); ok {
|
|
if s.metrics != nil {
|
|
s.metrics.IncrementMemCacheHitCounter(cache.Name())
|
|
}
|
|
result := NewSupplierResult()
|
|
result.Data = cacheItem
|
|
return result
|
|
}
|
|
|
|
if s.metrics != nil {
|
|
s.metrics.IncrementMemCacheMissCounter(cache.Name())
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (s *LocalCacheSupplier) doStandardAddToCache(ctx context.Context, cache utils.ObjectCache, key string, result *LayeredStoreSupplierResult, hints ...LayeredStoreHint) {
|
|
if result.Err == nil && result.Data != nil {
|
|
cache.AddWithDefaultExpires(key, result.Data)
|
|
}
|
|
}
|
|
|
|
func (s *LocalCacheSupplier) doInvalidateCacheCluster(cache utils.ObjectCache, key string) {
|
|
cache.Remove(key)
|
|
if s.cluster != nil {
|
|
msg := &model.ClusterMessage{
|
|
Event: cache.GetInvalidateClusterEvent(),
|
|
SendType: model.CLUSTER_SEND_BEST_EFFORT,
|
|
Data: key,
|
|
}
|
|
s.cluster.SendClusterMessage(msg)
|
|
}
|
|
}
|
|
|
|
func (s *LocalCacheSupplier) doClearCacheCluster(cache utils.ObjectCache) {
|
|
cache.Purge()
|
|
if s.cluster != nil {
|
|
msg := &model.ClusterMessage{
|
|
Event: cache.GetInvalidateClusterEvent(),
|
|
SendType: model.CLUSTER_SEND_BEST_EFFORT,
|
|
Data: CLEAR_CACHE_MESSAGE_DATA,
|
|
}
|
|
s.cluster.SendClusterMessage(msg)
|
|
}
|
|
}
|