Adding metrics for caching mechanisms (#4828)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
6a5cdd5cdf
Коммит
f96173528f
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
l4g "github.com/alecthomas/log4go"
|
||||
"github.com/go-gorp/gorp"
|
||||
"github.com/mattermost/platform/einterfaces"
|
||||
"github.com/mattermost/platform/model"
|
||||
"github.com/mattermost/platform/utils"
|
||||
)
|
||||
@@ -684,13 +685,21 @@ 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")
|
||||
}
|
||||
ids := cacheItem.(map[string]string)
|
||||
if _, ok := ids[channelId]; ok {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
} else {
|
||||
if metrics != nil {
|
||||
metrics.IncrementMemCacheMissCounter("All Channel Members for User")
|
||||
}
|
||||
}
|
||||
|
||||
if result := <-us.GetAllChannelMembersForUser(userId, true); result.Err != nil {
|
||||
@@ -746,13 +755,25 @@ 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")
|
||||
}
|
||||
result.Data = cacheItem.(map[string]string)
|
||||
storeChannel <- result
|
||||
close(storeChannel)
|
||||
return
|
||||
} else {
|
||||
if metrics != nil {
|
||||
metrics.IncrementMemCacheMissCounter("All Channel Members for User")
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if metrics != nil {
|
||||
metrics.IncrementMemCacheMissCounter("All Channel Members for User")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -788,16 +809,28 @@ func (us SqlChannelStore) InvalidateMemberCount(channelId string) {
|
||||
|
||||
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")
|
||||
}
|
||||
result.Data = cacheItem.(int64)
|
||||
storeChannel <- result
|
||||
close(storeChannel)
|
||||
return
|
||||
} else {
|
||||
if metrics != nil {
|
||||
metrics.IncrementMemCacheMissCounter("Channel Member Counts")
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if metrics != nil {
|
||||
metrics.IncrementMemCacheMissCounter("Channel Member Counts")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/mattermost/platform/einterfaces"
|
||||
"github.com/mattermost/platform/model"
|
||||
"github.com/mattermost/platform/utils"
|
||||
)
|
||||
@@ -227,16 +228,28 @@ func (s SqlPostStore) InvalidatePostEtagCache(channelId string) {
|
||||
|
||||
func (s SqlPostStore) GetEtag(channelId string, allowFromCache bool) StoreChannel {
|
||||
storeChannel := make(StoreChannel, 1)
|
||||
metrics := einterfaces.GetMetricsInterface()
|
||||
|
||||
go func() {
|
||||
result := StoreResult{}
|
||||
|
||||
if allowFromCache {
|
||||
if cacheItem, ok := postEtagCache.Get(channelId); ok {
|
||||
if metrics != nil {
|
||||
metrics.IncrementMemCacheHitCounter("Post Etag")
|
||||
}
|
||||
result.Data = cacheItem.(string)
|
||||
storeChannel <- result
|
||||
close(storeChannel)
|
||||
return
|
||||
} else {
|
||||
if metrics != nil {
|
||||
metrics.IncrementMemCacheMissCounter("Post Etag")
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if metrics != nil {
|
||||
metrics.IncrementMemCacheMissCounter("Post Etag")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/mattermost/platform/einterfaces"
|
||||
"github.com/mattermost/platform/model"
|
||||
"github.com/mattermost/platform/utils"
|
||||
)
|
||||
@@ -601,13 +602,25 @@ func (us SqlUserStore) GetProfilesInChannel(channelId string, offset int, limit
|
||||
|
||||
go func() {
|
||||
result := StoreResult{}
|
||||
metrics := einterfaces.GetMetricsInterface()
|
||||
|
||||
if allowFromCache && offset == -1 && limit == -1 {
|
||||
if cacheItem, ok := profilesInChannelCache.Get(channelId); ok {
|
||||
if metrics != nil {
|
||||
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")
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if metrics != nil {
|
||||
metrics.IncrementMemCacheMissCounter("Profiles in Channel")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user