summaryrefslogtreecommitdiffstats
path: root/store/sql_channel_store.go
diff options
context:
space:
mode:
Diffstat (limited to 'store/sql_channel_store.go')
-rw-r--r--store/sql_channel_store.go34
1 files changed, 29 insertions, 5 deletions
diff --git a/store/sql_channel_store.go b/store/sql_channel_store.go
index e3df07f74..7e90a6d27 100644
--- a/store/sql_channel_store.go
+++ b/store/sql_channel_store.go
@@ -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