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
Этот коммит содержится в:
коммит произвёл
Harrison Healey
родитель
0f07a2d288
Коммит
b212acf312
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Ссылка в новой задаче
Block a user