PLT-4430 improve slow channel switching (#4331)
* PLT-4430 improve slow channel switching * Update client side unit tests * Convert getChannelsUnread to getMyChannelMembers and address other feedback * Pull channel members on websocket reconnect
Этот коммит содержится в:
коммит произвёл
Harrison Healey
родитель
14ce471311
Коммит
f82667f3b8
@@ -367,23 +367,16 @@ func (s SqlChannelStore) GetChannels(teamId string, userId string) StoreChannel
|
||||
go func() {
|
||||
result := StoreResult{}
|
||||
|
||||
var data []channelWithMember
|
||||
_, err := s.GetReplica().Select(&data, "SELECT * FROM Channels, ChannelMembers WHERE Id = ChannelId AND UserId = :UserId AND DeleteAt = 0 AND (TeamId = :TeamId OR TeamId = '') ORDER BY DisplayName", map[string]interface{}{"TeamId": teamId, "UserId": userId})
|
||||
data := &model.ChannelList{}
|
||||
_, err := s.GetReplica().Select(data, "SELECT Channels.* FROM Channels, ChannelMembers WHERE Id = ChannelId AND UserId = :UserId AND DeleteAt = 0 AND (TeamId = :TeamId OR TeamId = '') ORDER BY DisplayName", map[string]interface{}{"TeamId": teamId, "UserId": userId})
|
||||
|
||||
if err != nil {
|
||||
result.Err = model.NewLocAppError("SqlChannelStore.GetChannels", "store.sql_channel.get_channels.get.app_error", nil, "teamId="+teamId+", userId="+userId+", err="+err.Error())
|
||||
} else {
|
||||
channels := &model.ChannelList{make([]*model.Channel, len(data)), make(map[string]*model.ChannelMember)}
|
||||
for i := range data {
|
||||
v := data[i]
|
||||
channels.Channels[i] = &v.Channel
|
||||
channels.Members[v.Channel.Id] = &v.ChannelMember
|
||||
}
|
||||
|
||||
if len(channels.Channels) == 0 {
|
||||
if len(*data) == 0 {
|
||||
result.Err = model.NewLocAppError("SqlChannelStore.GetChannels", "store.sql_channel.get_channels.not_found.app_error", nil, "teamId="+teamId+", userId="+userId)
|
||||
} else {
|
||||
result.Data = channels
|
||||
result.Data = data
|
||||
}
|
||||
}
|
||||
|
||||
@@ -400,8 +393,8 @@ func (s SqlChannelStore) GetMoreChannels(teamId string, userId string) StoreChan
|
||||
go func() {
|
||||
result := StoreResult{}
|
||||
|
||||
var data []*model.Channel
|
||||
_, err := s.GetReplica().Select(&data,
|
||||
data := &model.ChannelList{}
|
||||
_, err := s.GetReplica().Select(data,
|
||||
`SELECT
|
||||
*
|
||||
FROM
|
||||
@@ -426,7 +419,7 @@ func (s SqlChannelStore) GetMoreChannels(teamId string, userId string) StoreChan
|
||||
if err != nil {
|
||||
result.Err = model.NewLocAppError("SqlChannelStore.GetMoreChannels", "store.sql_channel.get_more_channels.get.app_error", nil, "teamId="+teamId+", userId="+userId+", err="+err.Error())
|
||||
} else {
|
||||
result.Data = &model.ChannelList{data, make(map[string]*model.ChannelMember)}
|
||||
result.Data = data
|
||||
}
|
||||
|
||||
storeChannel <- result
|
||||
@@ -918,11 +911,12 @@ func (s SqlChannelStore) IncrementMentionCount(channelId string, userId string)
|
||||
`UPDATE
|
||||
ChannelMembers
|
||||
SET
|
||||
MentionCount = MentionCount + 1
|
||||
MentionCount = MentionCount + 1,
|
||||
LastUpdateAt = :LastUpdateAt
|
||||
WHERE
|
||||
UserId = :UserId
|
||||
AND ChannelId = :ChannelId`,
|
||||
map[string]interface{}{"ChannelId": channelId, "UserId": userId})
|
||||
map[string]interface{}{"ChannelId": channelId, "UserId": userId, "LastUpdateAt": model.GetMillis()})
|
||||
if err != nil {
|
||||
result.Err = model.NewLocAppError("SqlChannelStore.IncrementMentionCount", "store.sql_channel.increment_mention_count.app_error", nil, "channel_id="+channelId+", user_id="+userId+", "+err.Error())
|
||||
}
|
||||
@@ -1032,3 +1026,32 @@ func (s SqlChannelStore) ExtraUpdateByUser(userId string, time int64) StoreChann
|
||||
|
||||
return storeChannel
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) GetMembersForUser(teamId string, userId string) StoreChannel {
|
||||
storeChannel := make(StoreChannel, 1)
|
||||
|
||||
go func() {
|
||||
result := StoreResult{}
|
||||
|
||||
members := &model.ChannelMembers{}
|
||||
_, err := s.GetReplica().Select(members, `
|
||||
SELECT cm.*
|
||||
FROM ChannelMembers cm
|
||||
INNER JOIN Channels c
|
||||
ON c.Id = cm.ChannelId
|
||||
AND c.TeamId = :TeamId
|
||||
WHERE cm.UserId = :UserId
|
||||
`, map[string]interface{}{"TeamId": teamId, "UserId": userId})
|
||||
|
||||
if err != nil {
|
||||
result.Err = model.NewLocAppError("SqlChannelStore.GetMembersForUser", "store.sql_channel.get_members.app_error", nil, "teamId="+teamId+", userId="+userId+", err="+err.Error())
|
||||
} else {
|
||||
result.Data = members
|
||||
}
|
||||
|
||||
storeChannel <- result
|
||||
close(storeChannel)
|
||||
}()
|
||||
|
||||
return storeChannel
|
||||
}
|
||||
|
||||
@@ -305,14 +305,14 @@ func TestChannelStoreDelete(t *testing.T) {
|
||||
cresult := <-store.Channel().GetChannels(o1.TeamId, m1.UserId)
|
||||
list := cresult.Data.(*model.ChannelList)
|
||||
|
||||
if len(list.Channels) != 1 {
|
||||
if len(*list) != 1 {
|
||||
t.Fatal("invalid number of channels")
|
||||
}
|
||||
|
||||
cresult = <-store.Channel().GetMoreChannels(o1.TeamId, m1.UserId)
|
||||
list = cresult.Data.(*model.ChannelList)
|
||||
|
||||
if len(list.Channels) != 1 {
|
||||
if len(*list) != 1 {
|
||||
t.Fatal("invalid number of channels")
|
||||
}
|
||||
}
|
||||
@@ -514,7 +514,7 @@ func TestChannelStoreGetChannels(t *testing.T) {
|
||||
cresult := <-store.Channel().GetChannels(o1.TeamId, m1.UserId)
|
||||
list := cresult.Data.(*model.ChannelList)
|
||||
|
||||
if list.Channels[0].Id != o1.Id {
|
||||
if (*list)[0].Id != o1.Id {
|
||||
t.Fatal("missing channel")
|
||||
}
|
||||
|
||||
@@ -614,11 +614,11 @@ func TestChannelStoreGetMoreChannels(t *testing.T) {
|
||||
cresult := <-store.Channel().GetMoreChannels(o1.TeamId, m1.UserId)
|
||||
list := cresult.Data.(*model.ChannelList)
|
||||
|
||||
if len(list.Channels) != 1 {
|
||||
if len(*list) != 1 {
|
||||
t.Fatal("wrong list")
|
||||
}
|
||||
|
||||
if list.Channels[0].Name != o3.Name {
|
||||
if (*list)[0].Name != o3.Name {
|
||||
t.Fatal("missing channel")
|
||||
}
|
||||
|
||||
@@ -688,6 +688,51 @@ func TestChannelStoreGetChannelCounts(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestChannelStoreGetMembersForUser(t *testing.T) {
|
||||
Setup()
|
||||
|
||||
t1 := model.Team{}
|
||||
t1.DisplayName = "Name"
|
||||
t1.Name = model.NewId()
|
||||
t1.Email = model.NewId() + "@nowhere.com"
|
||||
t1.Type = model.TEAM_OPEN
|
||||
Must(store.Team().Save(&t1))
|
||||
|
||||
o1 := model.Channel{}
|
||||
o1.TeamId = t1.Id
|
||||
o1.DisplayName = "Channel1"
|
||||
o1.Name = "a" + model.NewId() + "b"
|
||||
o1.Type = model.CHANNEL_OPEN
|
||||
Must(store.Channel().Save(&o1))
|
||||
|
||||
o2 := model.Channel{}
|
||||
o2.TeamId = o1.TeamId
|
||||
o2.DisplayName = "Channel2"
|
||||
o2.Name = "a" + model.NewId() + "b"
|
||||
o2.Type = model.CHANNEL_OPEN
|
||||
Must(store.Channel().Save(&o2))
|
||||
|
||||
m1 := model.ChannelMember{}
|
||||
m1.ChannelId = o1.Id
|
||||
m1.UserId = model.NewId()
|
||||
m1.NotifyProps = model.GetDefaultChannelNotifyProps()
|
||||
Must(store.Channel().SaveMember(&m1))
|
||||
|
||||
m2 := model.ChannelMember{}
|
||||
m2.ChannelId = o2.Id
|
||||
m2.UserId = m1.UserId
|
||||
m2.NotifyProps = model.GetDefaultChannelNotifyProps()
|
||||
Must(store.Channel().SaveMember(&m2))
|
||||
|
||||
cresult := <-store.Channel().GetMembersForUser(o1.TeamId, m1.UserId)
|
||||
members := cresult.Data.(*model.ChannelMembers)
|
||||
|
||||
// no unread messages
|
||||
if len(*members) != 2 {
|
||||
t.Fatal("wrong number of members")
|
||||
}
|
||||
}
|
||||
|
||||
func TestChannelStoreUpdateLastViewedAt(t *testing.T) {
|
||||
Setup()
|
||||
|
||||
|
||||
@@ -109,6 +109,7 @@ type ChannelStore interface {
|
||||
IncrementMentionCount(channelId string, userId string) StoreChannel
|
||||
AnalyticsTypeCount(teamId string, channelType string) StoreChannel
|
||||
ExtraUpdateByUser(userId string, time int64) StoreChannel
|
||||
GetMembersForUser(teamId string, userId string) StoreChannel
|
||||
}
|
||||
|
||||
type PostStore interface {
|
||||
|
||||
Ссылка в новой задаче
Block a user