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
Этот коммит содержится в:
enahum
2016-10-27 12:24:30 -03:00
коммит произвёл Harrison Healey
родитель 14ce471311
Коммит f82667f3b8
22 изменённых файлов: 271 добавлений и 117 удалений

Просмотреть файл

@@ -21,6 +21,7 @@ func InitChannel() {
BaseRoutes.Channels.Handle("/", ApiUserRequired(getChannels)).Methods("GET")
BaseRoutes.Channels.Handle("/more", ApiUserRequired(getMoreChannels)).Methods("GET")
BaseRoutes.Channels.Handle("/counts", ApiUserRequired(getChannelCounts)).Methods("GET")
BaseRoutes.Channels.Handle("/members", ApiUserRequired(getMyChannelMembers)).Methods("GET")
BaseRoutes.Channels.Handle("/create", ApiUserRequired(createChannel)).Methods("POST")
BaseRoutes.Channels.Handle("/create_direct", ApiUserRequired(createDirectChannel)).Methods("POST")
BaseRoutes.Channels.Handle("/update", ApiUserRequired(updateChannel)).Methods("POST")
@@ -81,7 +82,7 @@ func createChannel(c *Context, w http.ResponseWriter, r *http.Request) {
return
} else {
data := result.Data.(*model.ChannelList)
if int64(len(data.Channels)+1) > *utils.Cfg.TeamSettings.MaxChannelsPerTeam {
if int64(len(*data)+1) > *utils.Cfg.TeamSettings.MaxChannelsPerTeam {
c.Err = model.NewLocAppError("createChannel", "api.channel.create_channel.max_channel_limit.app_error", map[string]interface{}{"MaxChannelsPerTeam": *utils.Cfg.TeamSettings.MaxChannelsPerTeam}, "")
return
}
@@ -987,6 +988,16 @@ func getChannelMember(c *Context, w http.ResponseWriter, r *http.Request) {
}
}
func getMyChannelMembers(c *Context, w http.ResponseWriter, r *http.Request) {
if result := <-Srv.Store.Channel().GetMembersForUser(c.TeamId, c.Session.UserId); result.Err != nil {
c.Err = result.Err
return
} else {
data := result.Data.(*model.ChannelMembers)
w.Write([]byte(data.ToJson()))
}
}
func addMember(c *Context, w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
id := params["channel_id"]

Просмотреть файл

@@ -35,7 +35,7 @@ func TestCreateChannel(t *testing.T) {
rget := Client.Must(Client.GetChannels("")).Data.(*model.ChannelList)
nameMatch := false
for _, c := range rget.Channels {
for _, c := range *rget {
if c.Name == channel.Name {
nameMatch = true
}
@@ -240,8 +240,8 @@ func TestUpdateChannel(t *testing.T) {
}
rget := Client.Must(Client.GetChannels(""))
data := rget.Data.(*model.ChannelList)
for _, c := range data.Channels {
channels := rget.Data.(*model.ChannelList)
for _, c := range *channels {
if c.Name == model.DEFAULT_CHANNEL {
c.Header = "new header"
c.Name = "pseudo-square"
@@ -654,13 +654,13 @@ func TestGetChannel(t *testing.T) {
channel2 = Client.Must(Client.CreateChannel(channel2)).Data.(*model.Channel)
rget := Client.Must(Client.GetChannels(""))
data := rget.Data.(*model.ChannelList)
channels := rget.Data.(*model.ChannelList)
if data.Channels[0].DisplayName != channel1.DisplayName {
if (*channels)[0].DisplayName != channel1.DisplayName {
t.Fatal("full name didn't match")
}
if data.Channels[1].DisplayName != channel2.DisplayName {
if (*channels)[1].DisplayName != channel2.DisplayName {
t.Fatal("full name didn't match")
}
@@ -717,13 +717,13 @@ func TestGetMoreChannel(t *testing.T) {
th.LoginBasic2()
rget := Client.Must(Client.GetMoreChannels(""))
data := rget.Data.(*model.ChannelList)
channels := rget.Data.(*model.ChannelList)
if data.Channels[0].DisplayName != channel1.DisplayName {
if (*channels)[0].DisplayName != channel1.DisplayName {
t.Fatal("full name didn't match")
}
if data.Channels[1].DisplayName != channel2.DisplayName {
if (*channels)[1].DisplayName != channel2.DisplayName {
t.Fatal("full name didn't match")
}
@@ -770,6 +770,30 @@ func TestGetChannelCounts(t *testing.T) {
}
func TestGetMyChannelMembers(t *testing.T) {
th := Setup().InitBasic()
Client := th.BasicClient
team := th.BasicTeam
channel1 := &model.Channel{DisplayName: "A Test API Name", Name: "a" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id}
channel1 = Client.Must(Client.CreateChannel(channel1)).Data.(*model.Channel)
channel2 := &model.Channel{DisplayName: "B Test API Name", Name: "a" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id}
channel2 = Client.Must(Client.CreateChannel(channel2)).Data.(*model.Channel)
if result, err := Client.GetMyChannelMembers(); err != nil {
t.Fatal(err)
} else {
members := result.Data.(*model.ChannelMembers)
// town-square, off-topic, basic test channel, channel1, channel2
if len(*members) != 5 {
t.Fatal("wrong number of members", len(*members))
}
}
}
func TestJoinChannelById(t *testing.T) {
th := Setup().InitBasic()
Client := th.BasicClient
@@ -905,7 +929,7 @@ func TestLeaveChannel(t *testing.T) {
rget := Client.Must(Client.GetChannels(""))
cdata := rget.Data.(*model.ChannelList)
for _, c := range cdata.Channels {
for _, c := range *cdata {
if c.Name == model.DEFAULT_CHANNEL {
if _, err := Client.LeaveChannel(c.Id); err == nil {
t.Fatal("should have errored on leaving default channel")
@@ -969,7 +993,7 @@ func TestDeleteChannel(t *testing.T) {
rget := Client.Must(Client.GetChannels(""))
cdata := rget.Data.(*model.ChannelList)
for _, c := range cdata.Channels {
for _, c := range *cdata {
if c.Name == model.DEFAULT_CHANNEL {
if _, err := Client.DeleteChannel(c.Id); err == nil {
t.Fatal("should have errored on deleting default channel")
@@ -1249,7 +1273,7 @@ func TestUpdateNotifyProps(t *testing.T) {
data["user_id"] = user.Id
data["desktop"] = model.CHANNEL_NOTIFY_MENTION
timeBeforeUpdate := model.GetMillis()
//timeBeforeUpdate := model.GetMillis()
time.Sleep(100 * time.Millisecond)
// test updating desktop
@@ -1261,14 +1285,6 @@ func TestUpdateNotifyProps(t *testing.T) {
t.Fatalf("NotifyProps[\"mark_unread\"] changed to %v", notifyProps["mark_unread"])
}
rget := Client.Must(Client.GetChannels(""))
rdata := rget.Data.(*model.ChannelList)
if len(rdata.Members) == 0 || rdata.Members[channel1.Id].NotifyProps["desktop"] != data["desktop"] {
t.Fatal("NotifyProps[\"desktop\"] did not update properly")
} else if rdata.Members[channel1.Id].LastUpdateAt <= timeBeforeUpdate {
t.Fatal("LastUpdateAt did not update")
}
// test an empty update
delete(data, "desktop")

Просмотреть файл

@@ -38,7 +38,7 @@ func (me *JoinProvider) DoCommand(c *Context, channelId string, message string)
} else {
channels := result.Data.(*model.ChannelList)
for _, v := range channels.Channels {
for _, v := range *channels {
if v.Name == message {

Просмотреть файл

@@ -42,7 +42,7 @@ func TestJoinCommands(t *testing.T) {
c1 := Client.Must(Client.GetChannels("")).Data.(*model.ChannelList)
found := false
for _, c := range c1.Channels {
for _, c := range *c1 {
if c.Id == channel2.Id {
found = true
}

Просмотреть файл

@@ -325,20 +325,20 @@ func LeaveTeam(team *model.Team, user *model.User) *model.AppError {
teamMember = result.Data.(model.TeamMember)
}
var channelMembers *model.ChannelList
var channelList *model.ChannelList
if result := <-Srv.Store.Channel().GetChannels(team.Id, user.Id); result.Err != nil {
if result.Err.Id == "store.sql_channel.get_channels.not_found.app_error" {
channelMembers = &model.ChannelList{make([]*model.Channel, 0), make(map[string]*model.ChannelMember)}
channelList = &model.ChannelList{}
} else {
return result.Err
}
} else {
channelMembers = result.Data.(*model.ChannelList)
channelList = result.Data.(*model.ChannelList)
}
for _, channel := range channelMembers.Channels {
for _, channel := range *channelList {
if channel.Type != model.CHANNEL_DIRECT {
Srv.Store.User().InvalidateProfilesInChannelCache(channel.Id)
if result := <-Srv.Store.Channel().RemoveMember(channel.Id, user.Id); result.Err != nil {

Просмотреть файл

@@ -63,7 +63,7 @@ func TestCreateFromSignupTeam(t *testing.T) {
}
c1 := Client.Must(Client.GetChannels("")).Data.(*model.ChannelList)
if len(c1.Channels) != 2 {
if len(*c1) != 2 {
t.Fatal("default channels not created")
}
@@ -94,7 +94,7 @@ func TestCreateTeam(t *testing.T) {
Client.SetTeamId(rteam.Data.(*model.Team).Id)
c1 := Client.Must(Client.GetChannels("")).Data.(*model.ChannelList)
if len(c1.Channels) != 2 {
if len(*c1) != 2 {
t.Fatal("default channels not created")
}