From b6fb98a43176215f16fc52b64abebde51355e5c1 Mon Sep 17 00:00:00 2001 From: Chris Date: Thu, 14 Sep 2017 12:01:44 -0500 Subject: remove more global references (#7442) --- store/sql_user_store.go | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'store/sql_user_store.go') 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))) } } -- cgit v1.2.3-1-g7c22