summaryrefslogtreecommitdiffstats
path: root/store/sql_user_store.go
diff options
context:
space:
mode:
authorChris <ccbrown112@gmail.com>2017-09-14 12:01:44 -0500
committerHarrison Healey <harrisonmhealey@gmail.com>2017-09-14 13:01:44 -0400
commitb6fb98a43176215f16fc52b64abebde51355e5c1 (patch)
tree095a2006bdfdd30d1a9c4fc4e604924fc0f50225 /store/sql_user_store.go
parentaf81f7e48bd2afaaa8c71f78bf86bdc00b104e4d (diff)
downloadchat-b6fb98a43176215f16fc52b64abebde51355e5c1.tar.gz
chat-b6fb98a43176215f16fc52b64abebde51355e5c1.tar.bz2
chat-b6fb98a43176215f16fc52b64abebde51355e5c1.zip
remove more global references (#7442)
Diffstat (limited to 'store/sql_user_store.go')
-rw-r--r--store/sql_user_store.go32
1 files changed, 17 insertions, 15 deletions
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)))
}
}