summaryrefslogtreecommitdiffstats
path: root/store
diff options
context:
space:
mode:
authorCorey Hulen <corey@hulen.com>2016-11-24 05:26:45 -0800
committerHarrison Healey <harrisonmhealey@gmail.com>2016-11-24 08:26:45 -0500
commitb212acf312ad640455fa715427ac19e6930dc61d (patch)
tree8fb977e00bef33587c3199ad3617417b27fb6b8a /store
parent0f07a2d288bada5e08cd9a63047ee85ef60738f5 (diff)
downloadchat-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')
-rw-r--r--store/sql_channel_store.go36
-rw-r--r--store/sql_channel_store_test.go26
-rw-r--r--store/store.go3
3 files changed, 49 insertions, 16 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
diff --git a/store/sql_channel_store_test.go b/store/sql_channel_store_test.go
index 8a51d2ae3..6776a438b 100644
--- a/store/sql_channel_store_test.go
+++ b/store/sql_channel_store_test.go
@@ -384,14 +384,24 @@ func TestChannelMemberStore(t *testing.T) {
t.Fatal("Member update time incorrect")
}
- count := (<-store.Channel().GetMemberCount(o1.ChannelId)).Data.(int64)
+ count := (<-store.Channel().GetMemberCount(o1.ChannelId, true)).Data.(int64)
+ if count != 2 {
+ t.Fatal("should have saved 2 members")
+ }
+
+ count = (<-store.Channel().GetMemberCount(o1.ChannelId, true)).Data.(int64)
+ if count != 2 {
+ t.Fatal("should have saved 2 members")
+ }
+
+ count = (<-store.Channel().GetMemberCount(o1.ChannelId, false)).Data.(int64)
if count != 2 {
t.Fatal("should have saved 2 members")
}
Must(store.Channel().RemoveMember(o2.ChannelId, o2.UserId))
- count = (<-store.Channel().GetMemberCount(o1.ChannelId)).Data.(int64)
+ count = (<-store.Channel().GetMemberCount(o1.ChannelId, false)).Data.(int64)
if count != 1 {
t.Fatal("should have removed 1 member")
}
@@ -463,14 +473,14 @@ func TestChannelDeleteMemberStore(t *testing.T) {
t.Fatal("Member update time incorrect")
}
- count := (<-store.Channel().GetMemberCount(o1.ChannelId)).Data.(int64)
+ count := (<-store.Channel().GetMemberCount(o1.ChannelId, false)).Data.(int64)
if count != 2 {
t.Fatal("should have saved 2 members")
}
Must(store.Channel().PermanentDeleteMembersByUser(o2.UserId))
- count = (<-store.Channel().GetMemberCount(o1.ChannelId)).Data.(int64)
+ count = (<-store.Channel().GetMemberCount(o1.ChannelId, false)).Data.(int64)
if count != 1 {
t.Fatal("should have removed 1 member")
}
@@ -927,7 +937,7 @@ func TestGetMemberCount(t *testing.T) {
}
Must(store.Channel().SaveMember(&m1))
- if result := <-store.Channel().GetMemberCount(c1.Id); result.Err != nil {
+ if result := <-store.Channel().GetMemberCount(c1.Id, false); result.Err != nil {
t.Fatal("failed to get member count: %v", result.Err)
} else if result.Data.(int64) != 1 {
t.Fatal("got incorrect member count %v", result.Data)
@@ -947,7 +957,7 @@ func TestGetMemberCount(t *testing.T) {
}
Must(store.Channel().SaveMember(&m2))
- if result := <-store.Channel().GetMemberCount(c1.Id); result.Err != nil {
+ if result := <-store.Channel().GetMemberCount(c1.Id, false); result.Err != nil {
t.Fatal("failed to get member count: %v", result.Err)
} else if result.Data.(int64) != 2 {
t.Fatal("got incorrect member count %v", result.Data)
@@ -968,7 +978,7 @@ func TestGetMemberCount(t *testing.T) {
}
Must(store.Channel().SaveMember(&m3))
- if result := <-store.Channel().GetMemberCount(c1.Id); result.Err != nil {
+ if result := <-store.Channel().GetMemberCount(c1.Id, false); result.Err != nil {
t.Fatal("failed to get member count: %v", result.Err)
} else if result.Data.(int64) != 2 {
t.Fatal("got incorrect member count %v", result.Data)
@@ -989,7 +999,7 @@ func TestGetMemberCount(t *testing.T) {
}
Must(store.Channel().SaveMember(&m4))
- if result := <-store.Channel().GetMemberCount(c1.Id); result.Err != nil {
+ if result := <-store.Channel().GetMemberCount(c1.Id, false); result.Err != nil {
t.Fatal("failed to get member count: %v", result.Err)
} else if result.Data.(int64) != 2 {
t.Fatal("got incorrect member count %v", result.Data)
diff --git a/store/store.go b/store/store.go
index d0790263a..94c8416bd 100644
--- a/store/store.go
+++ b/store/store.go
@@ -103,7 +103,8 @@ type ChannelStore interface {
InvalidateAllChannelMembersForUser(userId string)
IsUserInChannelUseCache(userId string, channelId string) bool
GetMemberForPost(postId string, userId string) StoreChannel
- GetMemberCount(channelId string) StoreChannel
+ InvalidateMemberCount(channelId string)
+ GetMemberCount(channelId string, allowFromCache bool) StoreChannel
RemoveMember(channelId string, userId string) StoreChannel
PermanentDeleteMembersByUser(userId string) StoreChannel
UpdateLastViewedAt(channelId string, userId string) StoreChannel