diff options
author | Chris <ccbrown112@gmail.com> | 2017-09-14 12:01:44 -0500 |
---|---|---|
committer | Harrison Healey <harrisonmhealey@gmail.com> | 2017-09-14 13:01:44 -0400 |
commit | b6fb98a43176215f16fc52b64abebde51355e5c1 (patch) | |
tree | 095a2006bdfdd30d1a9c4fc4e604924fc0f50225 /store | |
parent | af81f7e48bd2afaaa8c71f78bf86bdc00b104e4d (diff) | |
download | chat-b6fb98a43176215f16fc52b64abebde51355e5c1.tar.gz chat-b6fb98a43176215f16fc52b64abebde51355e5c1.tar.bz2 chat-b6fb98a43176215f16fc52b64abebde51355e5c1.zip |
remove more global references (#7442)
Diffstat (limited to 'store')
-rw-r--r-- | store/layered_store.go | 5 | ||||
-rw-r--r-- | store/local_cache_supplier.go | 36 | ||||
-rw-r--r-- | store/local_cache_supplier_reactions.go | 10 | ||||
-rw-r--r-- | store/sql_channel_store.go | 88 | ||||
-rw-r--r-- | store/sql_emoji_store.go | 21 | ||||
-rw-r--r-- | store/sql_file_info_store.go | 22 | ||||
-rw-r--r-- | store/sql_post_store.go | 47 | ||||
-rw-r--r-- | store/sql_supplier.go | 15 | ||||
-rw-r--r-- | store/sql_user_store.go | 32 | ||||
-rw-r--r-- | store/sql_webhook_store.go | 17 |
10 files changed, 152 insertions, 141 deletions
diff --git a/store/layered_store.go b/store/layered_store.go index 84b3ab1f5..ac0713f57 100644 --- a/store/layered_store.go +++ b/store/layered_store.go @@ -7,6 +7,7 @@ import ( "context" l4g "github.com/alecthomas/log4go" + "github.com/mattermost/mattermost-server/einterfaces" "github.com/mattermost/mattermost-server/model" ) @@ -26,8 +27,8 @@ type LayeredStore struct { func NewLayeredStore() Store { store := &LayeredStore{ TmpContext: context.TODO(), - DatabaseLayer: NewSqlSupplier(), - LocalCacheLayer: NewLocalCacheSupplier(), + DatabaseLayer: NewSqlSupplier(einterfaces.GetMetricsInterface()), + LocalCacheLayer: NewLocalCacheSupplier(einterfaces.GetMetricsInterface(), einterfaces.GetClusterInterface()), } store.ReactionStore = &LayeredReactionStore{store} diff --git a/store/local_cache_supplier.go b/store/local_cache_supplier.go index a2f03db8e..91aa94768 100644 --- a/store/local_cache_supplier.go +++ b/store/local_cache_supplier.go @@ -21,11 +21,15 @@ const ( type LocalCacheSupplier struct { next LayeredStoreSupplier reactionCache *utils.Cache + metrics einterfaces.MetricsInterface + cluster einterfaces.ClusterInterface } -func NewLocalCacheSupplier() *LocalCacheSupplier { +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), + metrics: metrics, + cluster: cluster, } registerClusterHandlers(supplier) @@ -47,58 +51,56 @@ func (s *LocalCacheSupplier) Next() LayeredStoreSupplier { return s.next } -func doStandardReadCache(ctx context.Context, cache utils.ObjectCache, key string, hints ...LayeredStoreHint) *LayeredStoreSupplierResult { - metrics := einterfaces.GetMetricsInterface() - +func (s *LocalCacheSupplier) doStandardReadCache(ctx context.Context, cache utils.ObjectCache, key string, hints ...LayeredStoreHint) *LayeredStoreSupplierResult { if hintsContains(hints, LSH_NO_CACHE) { - if metrics != nil { - metrics.IncrementMemCacheMissCounter(cache.Name()) + if s.metrics != nil { + s.metrics.IncrementMemCacheMissCounter(cache.Name()) } return nil } if cacheItem, ok := cache.Get(key); ok { - if metrics != nil { - metrics.IncrementMemCacheHitCounter(cache.Name()) + if s.metrics != nil { + s.metrics.IncrementMemCacheHitCounter(cache.Name()) } result := NewSupplierResult() result.Data = cacheItem return result } - if metrics != nil { - metrics.IncrementMemCacheMissCounter(cache.Name()) + if s.metrics != nil { + s.metrics.IncrementMemCacheMissCounter(cache.Name()) } return nil } -func doStandardAddToCache(ctx context.Context, cache utils.ObjectCache, key string, result *LayeredStoreSupplierResult, hints ...LayeredStoreHint) { +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 doInvalidateCacheCluster(cache utils.ObjectCache, key string) { +func (s *LocalCacheSupplier) doInvalidateCacheCluster(cache utils.ObjectCache, key string) { cache.Remove(key) - if einterfaces.GetClusterInterface() != nil { + if s.cluster != nil { msg := &model.ClusterMessage{ Event: cache.GetInvalidateClusterEvent(), SendType: model.CLUSTER_SEND_BEST_EFFORT, Data: key, } - einterfaces.GetClusterInterface().SendClusterMessage(msg) + s.cluster.SendClusterMessage(msg) } } -func doClearCacheCluster(cache utils.ObjectCache) { +func (s *LocalCacheSupplier) doClearCacheCluster(cache utils.ObjectCache) { cache.Purge() - if einterfaces.GetClusterInterface() != nil { + if s.cluster != nil { msg := &model.ClusterMessage{ Event: cache.GetInvalidateClusterEvent(), SendType: model.CLUSTER_SEND_BEST_EFFORT, Data: CLEAR_CACHE_MESSAGE_DATA, } - einterfaces.GetClusterInterface().SendClusterMessage(msg) + s.cluster.SendClusterMessage(msg) } } diff --git a/store/local_cache_supplier_reactions.go b/store/local_cache_supplier_reactions.go index 102215941..a67cff2e4 100644 --- a/store/local_cache_supplier_reactions.go +++ b/store/local_cache_supplier_reactions.go @@ -18,23 +18,23 @@ func (s *LocalCacheSupplier) handleClusterInvalidateReaction(msg *model.ClusterM } func (s *LocalCacheSupplier) ReactionSave(ctx context.Context, reaction *model.Reaction, hints ...LayeredStoreHint) *LayeredStoreSupplierResult { - doInvalidateCacheCluster(s.reactionCache, reaction.PostId) + s.doInvalidateCacheCluster(s.reactionCache, reaction.PostId) return s.Next().ReactionSave(ctx, reaction, hints...) } func (s *LocalCacheSupplier) ReactionDelete(ctx context.Context, reaction *model.Reaction, hints ...LayeredStoreHint) *LayeredStoreSupplierResult { - doInvalidateCacheCluster(s.reactionCache, reaction.PostId) + s.doInvalidateCacheCluster(s.reactionCache, reaction.PostId) return s.Next().ReactionDelete(ctx, reaction, hints...) } func (s *LocalCacheSupplier) ReactionGetForPost(ctx context.Context, postId string, hints ...LayeredStoreHint) *LayeredStoreSupplierResult { - if result := doStandardReadCache(ctx, s.reactionCache, postId, hints...); result != nil { + if result := s.doStandardReadCache(ctx, s.reactionCache, postId, hints...); result != nil { return result } result := s.Next().ReactionGetForPost(ctx, postId, hints...) - doStandardAddToCache(ctx, s.reactionCache, postId, result, hints...) + s.doStandardAddToCache(ctx, s.reactionCache, postId, result, hints...) return result } @@ -42,6 +42,6 @@ func (s *LocalCacheSupplier) ReactionGetForPost(ctx context.Context, postId stri func (s *LocalCacheSupplier) ReactionDeleteAllWithEmojiName(ctx context.Context, emojiName string, hints ...LayeredStoreHint) *LayeredStoreSupplierResult { // This could be improved. Right now we just clear the whole // cache because we don't have a way find what post Ids have this emoji name. - doClearCacheCluster(s.reactionCache) + s.doClearCacheCluster(s.reactionCache) return s.Next().ReactionDeleteAllWithEmojiName(ctx, emojiName, hints...) } diff --git a/store/sql_channel_store.go b/store/sql_channel_store.go index c25e3dd3a..aefccbbac 100644 --- a/store/sql_channel_store.go +++ b/store/sql_channel_store.go @@ -36,6 +36,7 @@ const ( type SqlChannelStore struct { SqlStore + metrics einterfaces.MetricsInterface } var channelMemberCountsCache = utils.NewLru(CHANNEL_MEMBERS_COUNTS_CACHE_SIZE) @@ -52,8 +53,11 @@ func ClearChannelCaches() { channelByNameCache.Purge() } -func NewSqlChannelStore(sqlStore SqlStore) ChannelStore { - s := &SqlChannelStore{sqlStore} +func NewSqlChannelStore(sqlStore SqlStore, metrics einterfaces.MetricsInterface) ChannelStore { + s := &SqlChannelStore{ + SqlStore: sqlStore, + metrics: metrics, + } for _, db := range sqlStore.GetAllConns() { table := db.AddTableWithName(model.Channel{}, "Channels").SetKeys(false, "Id") @@ -391,7 +395,6 @@ func (s SqlChannelStore) get(id string, master bool, allowFromCache bool) StoreC go func() { result := StoreResult{} - metrics := einterfaces.GetMetricsInterface() var db *gorp.DbMap if master { @@ -402,21 +405,21 @@ func (s SqlChannelStore) get(id string, master bool, allowFromCache bool) StoreC if allowFromCache { if cacheItem, ok := channelCache.Get(id); ok { - if metrics != nil { - metrics.IncrementMemCacheHitCounter("Channel") + if s.metrics != nil { + s.metrics.IncrementMemCacheHitCounter("Channel") } result.Data = (cacheItem.(*model.Channel)).DeepCopy() storeChannel <- result close(storeChannel) return } else { - if metrics != nil { - metrics.IncrementMemCacheMissCounter("Channel") + if s.metrics != nil { + s.metrics.IncrementMemCacheMissCounter("Channel") } } } else { - if metrics != nil { - metrics.IncrementMemCacheMissCounter("Channel") + if s.metrics != nil { + s.metrics.IncrementMemCacheMissCounter("Channel") } } @@ -758,18 +761,17 @@ func (s SqlChannelStore) getByName(teamId string, name string, includeDeleted bo channel := model.Channel{} if allowFromCache { - metrics := einterfaces.GetMetricsInterface() if cacheItem, ok := channelByNameCache.Get(teamId + name); ok { - if metrics != nil { - metrics.IncrementMemCacheHitCounter("Channel By Name") + if s.metrics != nil { + s.metrics.IncrementMemCacheHitCounter("Channel By Name") } result.Data = cacheItem.(*model.Channel) storeChannel <- result close(storeChannel) return } else { - if metrics != nil { - metrics.IncrementMemCacheMissCounter("Channel By Name") + if s.metrics != nil { + s.metrics.IncrementMemCacheMissCounter("Channel By Name") } } } @@ -978,10 +980,9 @@ func (us SqlChannelStore) InvalidateAllChannelMembersForUser(userId string) { } func (us SqlChannelStore) IsUserInChannelUseCache(userId string, channelId string) bool { - metrics := einterfaces.GetMetricsInterface() if cacheItem, ok := allChannelMembersForUserCache.Get(userId); ok { - if metrics != nil { - metrics.IncrementMemCacheHitCounter("All Channel Members for User") + if us.metrics != nil { + us.metrics.IncrementMemCacheHitCounter("All Channel Members for User") } ids := cacheItem.(map[string]string) if _, ok := ids[channelId]; ok { @@ -990,8 +991,8 @@ func (us SqlChannelStore) IsUserInChannelUseCache(userId string, channelId strin return false } } else { - if metrics != nil { - metrics.IncrementMemCacheMissCounter("All Channel Members for User") + if us.metrics != nil { + us.metrics.IncrementMemCacheMissCounter("All Channel Members for User") } } @@ -1048,25 +1049,24 @@ func (s SqlChannelStore) GetAllChannelMembersForUser(userId string, allowFromCac go func() { result := StoreResult{} - metrics := einterfaces.GetMetricsInterface() if allowFromCache { if cacheItem, ok := allChannelMembersForUserCache.Get(userId); ok { - if metrics != nil { - metrics.IncrementMemCacheHitCounter("All Channel Members for User") + if s.metrics != nil { + s.metrics.IncrementMemCacheHitCounter("All Channel Members for User") } result.Data = cacheItem.(map[string]string) storeChannel <- result close(storeChannel) return } else { - if metrics != nil { - metrics.IncrementMemCacheMissCounter("All Channel Members for User") + if s.metrics != nil { + s.metrics.IncrementMemCacheMissCounter("All Channel Members for User") } } } else { - if metrics != nil { - metrics.IncrementMemCacheMissCounter("All Channel Members for User") + if s.metrics != nil { + s.metrics.IncrementMemCacheMissCounter("All Channel Members for User") } } @@ -1110,25 +1110,24 @@ func (s SqlChannelStore) GetAllChannelMembersNotifyPropsForChannel(channelId str go func() { result := StoreResult{} - metrics := einterfaces.GetMetricsInterface() if allowFromCache { if cacheItem, ok := allChannelMembersNotifyPropsForChannelCache.Get(channelId); ok { - if metrics != nil { - metrics.IncrementMemCacheHitCounter("All Channel Members Notify Props for Channel") + if s.metrics != nil { + s.metrics.IncrementMemCacheHitCounter("All Channel Members Notify Props for Channel") } result.Data = cacheItem.(map[string]model.StringMap) storeChannel <- result close(storeChannel) return } else { - if metrics != nil { - metrics.IncrementMemCacheMissCounter("All Channel Members Notify Props for Channel") + if s.metrics != nil { + s.metrics.IncrementMemCacheMissCounter("All Channel Members Notify Props for Channel") } } } else { - if metrics != nil { - metrics.IncrementMemCacheMissCounter("All Channel Members Notify Props for Channel") + if s.metrics != nil { + s.metrics.IncrementMemCacheMissCounter("All Channel Members Notify Props for Channel") } } @@ -1164,16 +1163,14 @@ func (us SqlChannelStore) InvalidateMemberCount(channelId string) { } func (s SqlChannelStore) GetMemberCountFromCache(channelId string) int64 { - metrics := einterfaces.GetMetricsInterface() - if cacheItem, ok := channelMemberCountsCache.Get(channelId); ok { - if metrics != nil { - metrics.IncrementMemCacheHitCounter("Channel Member Counts") + if s.metrics != nil { + s.metrics.IncrementMemCacheHitCounter("Channel Member Counts") } return cacheItem.(int64) } else { - if metrics != nil { - metrics.IncrementMemCacheMissCounter("Channel Member Counts") + if s.metrics != nil { + s.metrics.IncrementMemCacheMissCounter("Channel Member Counts") } } @@ -1186,28 +1183,27 @@ func (s SqlChannelStore) GetMemberCountFromCache(channelId string) int64 { func (s SqlChannelStore) GetMemberCount(channelId string, allowFromCache bool) StoreChannel { storeChannel := make(StoreChannel, 1) - metrics := einterfaces.GetMetricsInterface() go func() { result := StoreResult{} if allowFromCache { if cacheItem, ok := channelMemberCountsCache.Get(channelId); ok { - if metrics != nil { - metrics.IncrementMemCacheHitCounter("Channel Member Counts") + if s.metrics != nil { + s.metrics.IncrementMemCacheHitCounter("Channel Member Counts") } result.Data = cacheItem.(int64) storeChannel <- result close(storeChannel) return } else { - if metrics != nil { - metrics.IncrementMemCacheMissCounter("Channel Member Counts") + if s.metrics != nil { + s.metrics.IncrementMemCacheMissCounter("Channel Member Counts") } } } else { - if metrics != nil { - metrics.IncrementMemCacheMissCounter("Channel Member Counts") + if s.metrics != nil { + s.metrics.IncrementMemCacheMissCounter("Channel Member Counts") } } diff --git a/store/sql_emoji_store.go b/store/sql_emoji_store.go index 5fd49ab3b..efab82d1f 100644 --- a/store/sql_emoji_store.go +++ b/store/sql_emoji_store.go @@ -20,10 +20,14 @@ var emojiCache *utils.Cache = utils.NewLru(EMOJI_CACHE_SIZE) type SqlEmojiStore struct { SqlStore + metrics einterfaces.MetricsInterface } -func NewSqlEmojiStore(sqlStore SqlStore) EmojiStore { - s := &SqlEmojiStore{sqlStore} +func NewSqlEmojiStore(sqlStore SqlStore, metrics einterfaces.MetricsInterface) EmojiStore { + s := &SqlEmojiStore{ + SqlStore: sqlStore, + metrics: metrics, + } for _, db := range sqlStore.GetAllConns() { table := db.AddTableWithName(model.Emoji{}, "Emoji").SetKeys(false, "Id") @@ -74,25 +78,24 @@ func (es SqlEmojiStore) Get(id string, allowFromCache bool) StoreChannel { go func() { result := StoreResult{} - metrics := einterfaces.GetMetricsInterface() if allowFromCache { if cacheItem, ok := emojiCache.Get(id); ok { - if metrics != nil { - metrics.IncrementMemCacheHitCounter("Emoji") + if es.metrics != nil { + es.metrics.IncrementMemCacheHitCounter("Emoji") } result.Data = cacheItem.(*model.Emoji) storeChannel <- result close(storeChannel) return } else { - if metrics != nil { - metrics.IncrementMemCacheMissCounter("Emoji") + if es.metrics != nil { + es.metrics.IncrementMemCacheMissCounter("Emoji") } } } else { - if metrics != nil { - metrics.IncrementMemCacheMissCounter("Emoji") + if es.metrics != nil { + es.metrics.IncrementMemCacheMissCounter("Emoji") } } diff --git a/store/sql_file_info_store.go b/store/sql_file_info_store.go index fc4a9513f..eab83992f 100644 --- a/store/sql_file_info_store.go +++ b/store/sql_file_info_store.go @@ -13,6 +13,7 @@ import ( type SqlFileInfoStore struct { SqlStore + metrics einterfaces.MetricsInterface } const ( @@ -26,8 +27,11 @@ func ClearFileCaches() { fileInfoCache.Purge() } -func NewSqlFileInfoStore(sqlStore SqlStore) FileInfoStore { - s := &SqlFileInfoStore{sqlStore} +func NewSqlFileInfoStore(sqlStore SqlStore, metrics einterfaces.MetricsInterface) FileInfoStore { + s := &SqlFileInfoStore{ + SqlStore: sqlStore, + metrics: metrics, + } for _, db := range sqlStore.GetAllConns() { table := db.AddTableWithName(model.FileInfo{}, "FileInfo").SetKeys(false, "Id") @@ -149,12 +153,10 @@ func (fs SqlFileInfoStore) GetForPost(postId string, readFromMaster bool, allowF go func() { result := StoreResult{} - metrics := einterfaces.GetMetricsInterface() - if allowFromCache { if cacheItem, ok := fileInfoCache.Get(postId); ok { - if metrics != nil { - metrics.IncrementMemCacheHitCounter("File Info Cache") + if fs.metrics != nil { + fs.metrics.IncrementMemCacheHitCounter("File Info Cache") } result.Data = cacheItem.([]*model.FileInfo) @@ -162,13 +164,13 @@ func (fs SqlFileInfoStore) GetForPost(postId string, readFromMaster bool, allowF close(storeChannel) return } else { - if metrics != nil { - metrics.IncrementMemCacheMissCounter("File Info Cache") + if fs.metrics != nil { + fs.metrics.IncrementMemCacheMissCounter("File Info Cache") } } } else { - if metrics != nil { - metrics.IncrementMemCacheMissCounter("File Info Cache") + if fs.metrics != nil { + fs.metrics.IncrementMemCacheMissCounter("File Info Cache") } } diff --git a/store/sql_post_store.go b/store/sql_post_store.go index d823bdc22..2aa862218 100644 --- a/store/sql_post_store.go +++ b/store/sql_post_store.go @@ -18,6 +18,7 @@ import ( type SqlPostStore struct { SqlStore + metrics einterfaces.MetricsInterface } const ( @@ -36,8 +37,11 @@ func ClearPostCaches() { lastPostsCache.Purge() } -func NewSqlPostStore(sqlStore SqlStore) PostStore { - s := &SqlPostStore{sqlStore} +func NewSqlPostStore(sqlStore SqlStore, metrics einterfaces.MetricsInterface) PostStore { + s := &SqlPostStore{ + SqlStore: sqlStore, + metrics: metrics, + } for _, db := range sqlStore.GetAllConns() { table := db.AddTableWithName(model.Post{}, "Posts").SetKeys(false, "Id") @@ -398,25 +402,24 @@ func (s SqlPostStore) GetEtag(channelId string, allowFromCache bool) StoreChanne go func() { result := StoreResult{} - metrics := einterfaces.GetMetricsInterface() if allowFromCache { if cacheItem, ok := lastPostTimeCache.Get(channelId); ok { - if metrics != nil { - metrics.IncrementMemCacheHitCounter("Last Post Time") + if s.metrics != nil { + s.metrics.IncrementMemCacheHitCounter("Last Post Time") } result.Data = fmt.Sprintf("%v.%v", model.CurrentVersion, cacheItem.(int64)) storeChannel <- result close(storeChannel) return } else { - if metrics != nil { - metrics.IncrementMemCacheMissCounter("Last Post Time") + if s.metrics != nil { + s.metrics.IncrementMemCacheMissCounter("Last Post Time") } } } else { - if metrics != nil { - metrics.IncrementMemCacheMissCounter("Last Post Time") + if s.metrics != nil { + s.metrics.IncrementMemCacheMissCounter("Last Post Time") } } @@ -570,7 +573,6 @@ func (s SqlPostStore) GetPosts(channelId string, offset int, limit int, allowFro go func() { result := StoreResult{} - metrics := einterfaces.GetMetricsInterface() if limit > 1000 { result.Err = model.NewLocAppError("SqlPostStore.GetLinearPosts", "store.sql_post.get_posts.app_error", nil, "channelId="+channelId) @@ -581,8 +583,8 @@ func (s SqlPostStore) GetPosts(channelId string, offset int, limit int, allowFro if allowFromCache && offset == 0 && limit == 60 { if cacheItem, ok := lastPostsCache.Get(channelId); ok { - if metrics != nil { - metrics.IncrementMemCacheHitCounter("Last Posts Cache") + if s.metrics != nil { + s.metrics.IncrementMemCacheHitCounter("Last Posts Cache") } result.Data = cacheItem.(*model.PostList) @@ -590,13 +592,13 @@ func (s SqlPostStore) GetPosts(channelId string, offset int, limit int, allowFro close(storeChannel) return } else { - if metrics != nil { - metrics.IncrementMemCacheMissCounter("Last Posts Cache") + if s.metrics != nil { + s.metrics.IncrementMemCacheMissCounter("Last Posts Cache") } } } else { - if metrics != nil { - metrics.IncrementMemCacheMissCounter("Last Posts Cache") + if s.metrics != nil { + s.metrics.IncrementMemCacheMissCounter("Last Posts Cache") } } @@ -643,14 +645,13 @@ func (s SqlPostStore) GetPostsSince(channelId string, time int64, allowFromCache go func() { result := StoreResult{} - metrics := einterfaces.GetMetricsInterface() if allowFromCache { // If the last post in the channel's time is less than or equal to the time we are getting posts since, // we can safely return no posts. if cacheItem, ok := lastPostTimeCache.Get(channelId); ok && cacheItem.(int64) <= time { - if metrics != nil { - metrics.IncrementMemCacheHitCounter("Last Post Time") + if s.metrics != nil { + s.metrics.IncrementMemCacheHitCounter("Last Post Time") } list := model.NewPostList() result.Data = list @@ -658,13 +659,13 @@ func (s SqlPostStore) GetPostsSince(channelId string, time int64, allowFromCache close(storeChannel) return } else { - if metrics != nil { - metrics.IncrementMemCacheMissCounter("Last Post Time") + if s.metrics != nil { + s.metrics.IncrementMemCacheMissCounter("Last Post Time") } } } else { - if metrics != nil { - metrics.IncrementMemCacheMissCounter("Last Post Time") + if s.metrics != nil { + s.metrics.IncrementMemCacheMissCounter("Last Post Time") } } diff --git a/store/sql_supplier.go b/store/sql_supplier.go index b6dd77cd1..f839bbed5 100644 --- a/store/sql_supplier.go +++ b/store/sql_supplier.go @@ -19,6 +19,7 @@ import ( "github.com/go-sql-driver/mysql" "github.com/lib/pq" "github.com/mattermost/gorp" + "github.com/mattermost/mattermost-server/einterfaces" "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/utils" ) @@ -96,7 +97,7 @@ type SqlSupplier struct { oldStores SqlSupplierOldStores } -func NewSqlSupplier() *SqlSupplier { +func NewSqlSupplier(metrics einterfaces.MetricsInterface) *SqlSupplier { supplier := &SqlSupplier{ rrCounter: 0, srCounter: 0, @@ -105,24 +106,24 @@ func NewSqlSupplier() *SqlSupplier { supplier.initConnection() supplier.oldStores.team = NewSqlTeamStore(supplier) - supplier.oldStores.channel = NewSqlChannelStore(supplier) - supplier.oldStores.post = NewSqlPostStore(supplier) - supplier.oldStores.user = NewSqlUserStore(supplier) + supplier.oldStores.channel = NewSqlChannelStore(supplier, metrics) + supplier.oldStores.post = NewSqlPostStore(supplier, metrics) + supplier.oldStores.user = NewSqlUserStore(supplier, metrics) supplier.oldStores.audit = NewSqlAuditStore(supplier) supplier.oldStores.cluster = NewSqlClusterDiscoveryStore(supplier) supplier.oldStores.compliance = NewSqlComplianceStore(supplier) supplier.oldStores.session = NewSqlSessionStore(supplier) supplier.oldStores.oauth = NewSqlOAuthStore(supplier) supplier.oldStores.system = NewSqlSystemStore(supplier) - supplier.oldStores.webhook = NewSqlWebhookStore(supplier) + supplier.oldStores.webhook = NewSqlWebhookStore(supplier, metrics) supplier.oldStores.command = NewSqlCommandStore(supplier) supplier.oldStores.commandWebhook = NewSqlCommandWebhookStore(supplier) supplier.oldStores.preference = NewSqlPreferenceStore(supplier) supplier.oldStores.license = NewSqlLicenseStore(supplier) supplier.oldStores.token = NewSqlTokenStore(supplier) - supplier.oldStores.emoji = NewSqlEmojiStore(supplier) + supplier.oldStores.emoji = NewSqlEmojiStore(supplier, metrics) supplier.oldStores.status = NewSqlStatusStore(supplier) - supplier.oldStores.fileInfo = NewSqlFileInfoStore(supplier) + supplier.oldStores.fileInfo = NewSqlFileInfoStore(supplier, metrics) supplier.oldStores.job = NewSqlJobStore(supplier) supplier.oldStores.userAccessToken = NewSqlUserAccessTokenStore(supplier) diff --git a/store/sql_user_store.go b/store/sql_user_store.go index a162ab4b6..6d8b116b3 100644 --- a/store/sql_user_store.go +++ b/store/sql_user_store.go @@ -34,6 +34,7 @@ const ( type SqlUserStore struct { SqlStore + metrics einterfaces.MetricsInterface } var profilesInChannelCache *utils.Cache = utils.NewLru(PROFILES_IN_CHANNEL_CACHE_SIZE) @@ -48,8 +49,11 @@ func (us SqlUserStore) InvalidatProfileCacheForUser(userId string) { profileByIdsCache.Remove(userId) } -func NewSqlUserStore(sqlStore SqlStore) UserStore { - us := &SqlUserStore{sqlStore} +func NewSqlUserStore(sqlStore SqlStore, metrics einterfaces.MetricsInterface) UserStore { + us := &SqlUserStore{ + SqlStore: sqlStore, + metrics: metrics, + } for _, db := range sqlStore.GetAllConns() { table := db.AddTableWithName(model.User{}, "Users").SetKeys(false, "Id") @@ -572,25 +576,24 @@ func (us SqlUserStore) GetAllProfilesInChannel(channelId string, allowFromCache go func() { result := StoreResult{} - metrics := einterfaces.GetMetricsInterface() if allowFromCache { if cacheItem, ok := profilesInChannelCache.Get(channelId); ok { - if metrics != nil { - metrics.IncrementMemCacheHitCounter("Profiles in Channel") + if us.metrics != nil { + us.metrics.IncrementMemCacheHitCounter("Profiles in Channel") } result.Data = cacheItem.(map[string]*model.User) storeChannel <- result close(storeChannel) return } else { - if metrics != nil { - metrics.IncrementMemCacheMissCounter("Profiles in Channel") + if us.metrics != nil { + us.metrics.IncrementMemCacheMissCounter("Profiles in Channel") } } } else { - if metrics != nil { - metrics.IncrementMemCacheMissCounter("Profiles in Channel") + if us.metrics != nil { + us.metrics.IncrementMemCacheMissCounter("Profiles in Channel") } } @@ -838,7 +841,6 @@ func (us SqlUserStore) GetProfileByIds(userIds []string, allowFromCache bool) St go func() { result := StoreResult{} - metrics := einterfaces.GetMetricsInterface() users := []*model.User{} props := make(map[string]interface{}) @@ -855,14 +857,14 @@ func (us SqlUserStore) GetProfileByIds(userIds []string, allowFromCache bool) St remainingUserIds = append(remainingUserIds, userId) } } - if metrics != nil { - metrics.AddMemCacheHitCounter("Profile By Ids", float64(len(users))) - metrics.AddMemCacheMissCounter("Profile By Ids", float64(len(remainingUserIds))) + if us.metrics != nil { + us.metrics.AddMemCacheHitCounter("Profile By Ids", float64(len(users))) + us.metrics.AddMemCacheMissCounter("Profile By Ids", float64(len(remainingUserIds))) } } else { remainingUserIds = userIds - if metrics != nil { - metrics.AddMemCacheMissCounter("Profile By Ids", float64(len(remainingUserIds))) + if us.metrics != nil { + us.metrics.AddMemCacheMissCounter("Profile By Ids", float64(len(remainingUserIds))) } } diff --git a/store/sql_webhook_store.go b/store/sql_webhook_store.go index 5cc2df43c..a43e78fc4 100644 --- a/store/sql_webhook_store.go +++ b/store/sql_webhook_store.go @@ -15,6 +15,7 @@ import ( type SqlWebhookStore struct { SqlStore + metrics einterfaces.MetricsInterface } const ( @@ -28,8 +29,11 @@ func ClearWebhookCaches() { webhookCache.Purge() } -func NewSqlWebhookStore(sqlStore SqlStore) WebhookStore { - s := &SqlWebhookStore{sqlStore} +func NewSqlWebhookStore(sqlStore SqlStore, metrics einterfaces.MetricsInterface) WebhookStore { + s := &SqlWebhookStore{ + SqlStore: sqlStore, + metrics: metrics, + } for _, db := range sqlStore.GetAllConns() { table := db.AddTableWithName(model.IncomingWebhook{}, "IncomingWebhooks").SetKeys(false, "Id") @@ -137,18 +141,17 @@ func (s SqlWebhookStore) GetIncoming(id string, allowFromCache bool) StoreChanne result := StoreResult{} if allowFromCache { - metrics := einterfaces.GetMetricsInterface() if cacheItem, ok := webhookCache.Get(id); ok { - if metrics != nil { - metrics.IncrementMemCacheHitCounter("Webhook") + if s.metrics != nil { + s.metrics.IncrementMemCacheHitCounter("Webhook") } result.Data = cacheItem.(*model.IncomingWebhook) storeChannel <- result close(storeChannel) return } else { - if metrics != nil { - metrics.IncrementMemCacheMissCounter("Webhook") + if s.metrics != nil { + s.metrics.IncrementMemCacheMissCounter("Webhook") } } } |