diff options
author | Corey Hulen <corey@hulen.com> | 2016-11-24 05:26:45 -0800 |
---|---|---|
committer | Harrison Healey <harrisonmhealey@gmail.com> | 2016-11-24 08:26:45 -0500 |
commit | b212acf312ad640455fa715427ac19e6930dc61d (patch) | |
tree | 8fb977e00bef33587c3199ad3617417b27fb6b8a /store/sql_channel_store.go | |
parent | 0f07a2d288bada5e08cd9a63047ee85ef60738f5 (diff) | |
download | chat-b212acf312ad640455fa715427ac19e6930dc61d.tar.gz chat-b212acf312ad640455fa715427ac19e6930dc61d.tar.bz2 chat-b212acf312ad640455fa715427ac19e6930dc61d.zip |
PLT-4429 disabling at_all at_channel metions mentions when channel has more than 1k users (#4627)
* PLT-4429 disabling explicit mentions when channel has more than 1k users
* Fixing test case
* Adding setting to the admin console
* Fixing bad translation
Diffstat (limited to 'store/sql_channel_store.go')
-rw-r--r-- | store/sql_channel_store.go | 36 |
1 files changed, 29 insertions, 7 deletions
diff --git a/store/sql_channel_store.go b/store/sql_channel_store.go index aadeed7c3..207484532 100644 --- a/store/sql_channel_store.go +++ b/store/sql_channel_store.go @@ -13,18 +13,23 @@ import ( ) const ( - MISSING_CHANNEL_ERROR = "store.sql_channel.get_by_name.missing.app_error" - MISSING_CHANNEL_MEMBER_ERROR = "store.sql_channel.get_member.missing.app_error" - CHANNEL_EXISTS_ERROR = "store.sql_channel.save_channel.exists.app_error" + MISSING_CHANNEL_ERROR = "store.sql_channel.get_by_name.missing.app_error" + MISSING_CHANNEL_MEMBER_ERROR = "store.sql_channel.get_member.missing.app_error" + CHANNEL_EXISTS_ERROR = "store.sql_channel.save_channel.exists.app_error" + ALL_CHANNEL_MEMBERS_FOR_USER_CACHE_SIZE = model.SESSION_CACHE_SIZE ALL_CHANNEL_MEMBERS_FOR_USER_CACHE_SEC = 900 // 15 mins + + CHANNEL_MEMBERS_COUNTS_CACHE_SIZE = 20000 + CHANNEL_MEMBERS_COUNTS_CACHE_SEC = 900 // 15 mins ) type SqlChannelStore struct { *SqlStore } -var allChannelMembersForUserCache *utils.Cache = utils.NewLru(ALL_CHANNEL_MEMBERS_FOR_USER_CACHE_SIZE) +var channelMemberCountsCache = utils.NewLru(CHANNEL_MEMBERS_COUNTS_CACHE_SIZE) +var allChannelMembersForUserCache = utils.NewLru(ALL_CHANNEL_MEMBERS_FOR_USER_CACHE_SIZE) func NewSqlChannelStore(sqlStore *SqlStore) ChannelStore { s := &SqlChannelStore{sqlStore} @@ -395,7 +400,7 @@ func (s SqlChannelStore) GetMoreChannels(teamId string, userId string) StoreChan data := &model.ChannelList{} _, err := s.GetReplica().Select(data, - `SELECT + `SELECT * FROM Channels @@ -403,7 +408,7 @@ func (s SqlChannelStore) GetMoreChannels(teamId string, userId string) StoreChan TeamId = :TeamId1 AND Type IN ('O') AND DeleteAt = 0 - AND Id NOT IN (SELECT + AND Id NOT IN (SELECT Channels.Id FROM Channels, @@ -751,12 +756,25 @@ func (s SqlChannelStore) GetAllChannelMembersForUser(userId string, allowFromCac return storeChannel } -func (s SqlChannelStore) GetMemberCount(channelId string) StoreChannel { +func (us SqlChannelStore) InvalidateMemberCount(channelId string) { + channelMemberCountsCache.Remove(channelId) +} + +func (s SqlChannelStore) GetMemberCount(channelId string, allowFromCache bool) StoreChannel { storeChannel := make(StoreChannel, 1) go func() { result := StoreResult{} + if allowFromCache { + if cacheItem, ok := channelMemberCountsCache.Get(channelId); ok { + result.Data = cacheItem.(int64) + storeChannel <- result + close(storeChannel) + return + } + } + count, err := s.GetReplica().SelectInt(` SELECT count(*) @@ -771,6 +789,10 @@ func (s SqlChannelStore) GetMemberCount(channelId string) StoreChannel { result.Err = model.NewLocAppError("SqlChannelStore.GetMemberCount", "store.sql_channel.get_member_count.app_error", nil, "channel_id="+channelId+", "+err.Error()) } else { result.Data = count + + if allowFromCache { + channelMemberCountsCache.AddWithExpiresInSecs(channelId, count, CHANNEL_MEMBERS_COUNTS_CACHE_SEC) + } } storeChannel <- result |