Merge 3.6.2 into master (#5211)
* Add webhook cache * Add channel by name cache * Fxing profiles in channels cache * Fix merge
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
8eab04e944
Коммит
097289f8e4
@@ -38,11 +38,13 @@ type SqlChannelStore struct {
|
||||
var channelMemberCountsCache = utils.NewLru(CHANNEL_MEMBERS_COUNTS_CACHE_SIZE)
|
||||
var allChannelMembersForUserCache = utils.NewLru(ALL_CHANNEL_MEMBERS_FOR_USER_CACHE_SIZE)
|
||||
var channelCache = utils.NewLru(CHANNEL_CACHE_SIZE)
|
||||
var channelByNameCache = utils.NewLru(CHANNEL_CACHE_SIZE)
|
||||
|
||||
func ClearChannelCaches() {
|
||||
channelMemberCountsCache.Purge()
|
||||
allChannelMembersForUserCache.Purge()
|
||||
channelCache.Purge()
|
||||
channelByNameCache.Purge()
|
||||
}
|
||||
|
||||
func NewSqlChannelStore(sqlStore *SqlStore) ChannelStore {
|
||||
@@ -306,6 +308,10 @@ func (us SqlChannelStore) InvalidateChannel(id string) {
|
||||
channelCache.Remove(id)
|
||||
}
|
||||
|
||||
func (us SqlChannelStore) InvalidateChannelByName(teamId, name string) {
|
||||
channelCache.Remove(teamId + name)
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) Get(id string, allowFromCache bool) StoreChannel {
|
||||
return s.get(id, false, allowFromCache)
|
||||
}
|
||||
@@ -539,15 +545,15 @@ func (s SqlChannelStore) GetTeamChannels(teamId string) StoreChannel {
|
||||
return storeChannel
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) GetByName(teamId string, name string) StoreChannel {
|
||||
return s.getByName(teamId, name, false)
|
||||
func (s SqlChannelStore) GetByName(teamId string, name string, allowFromCache bool) StoreChannel {
|
||||
return s.getByName(teamId, name, false, allowFromCache)
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) GetByNameIncludeDeleted(teamId string, name string) StoreChannel {
|
||||
return s.getByName(teamId, name, true)
|
||||
func (s SqlChannelStore) GetByNameIncludeDeleted(teamId string, name string, allowFromCache bool) StoreChannel {
|
||||
return s.getByName(teamId, name, true, allowFromCache)
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) getByName(teamId string, name string, includeDeleted bool) StoreChannel {
|
||||
func (s SqlChannelStore) getByName(teamId string, name string, includeDeleted bool, allowFromCache bool) StoreChannel {
|
||||
storeChannel := make(StoreChannel, 1)
|
||||
|
||||
var query string
|
||||
@@ -562,6 +568,23 @@ 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")
|
||||
}
|
||||
result.Data = cacheItem.(*model.Channel)
|
||||
storeChannel <- result
|
||||
close(storeChannel)
|
||||
return
|
||||
} else {
|
||||
if metrics != nil {
|
||||
metrics.IncrementMemCacheMissCounter("Channel By Name")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if err := s.GetReplica().SelectOne(&channel, query, map[string]interface{}{"TeamId": teamId, "Name": name}); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
result.Err = model.NewLocAppError("SqlChannelStore.GetByName", MISSING_CHANNEL_ERROR, nil, "teamId="+teamId+", "+"name="+name+", "+err.Error())
|
||||
@@ -570,6 +593,7 @@ func (s SqlChannelStore) getByName(teamId string, name string, includeDeleted bo
|
||||
}
|
||||
} else {
|
||||
result.Data = &channel
|
||||
channelByNameCache.AddWithExpiresInSecs(teamId+name, &channel, CHANNEL_CACHE_SEC)
|
||||
}
|
||||
|
||||
storeChannel <- result
|
||||
|
||||
Ссылка в новой задаче
Block a user