MM-56906: Remove redundant calls on team switch (#30771)

On page load, we load ALL channels and channel members from all teams.
But then, on team_switch, we would again load channels and channel
members from that team. This was redundant and mainly kept
because previously the websocket events were considered unreliable.

Now with reliable websockets, and client-side pings, we can detect
broken connections faster and recover without loss.

Additionally, the getAllChannelMembers call would page through
all responses on the client side. This was inefficient and incur
extra latency. To optimize for this, we introduce server-side
streaming of the full response if page is set to -1.

This optimizes the intial response as well.

https://mattermost.atlassian.net/browse/MM-56906

```release-note
Optimize team switch operation by removing calls to get channels
and channel members.
```


Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
Agniva De Sarker
2025-05-12 20:05:46 +05:30
коммит произвёл GitHub
родитель 883711c72d
Коммит 4803892492
20 изменённых файлов: 376 добавлений и 49 удалений

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

@@ -108,6 +108,12 @@ type ChannelMemberForExport struct {
Username string
}
type ChannelMemberCursor struct {
Page int // If page is -1, then FromChannelID is used as a cursor.
PerPage int
FromChannelID string
}
func (o *ChannelMember) IsValid() *AppError {
if !IsValidId(o.ChannelId) {
return NewAppError("ChannelMember.IsValid", "model.channel_member.is_valid.channel_id.app_error", nil, "", http.StatusBadRequest)

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

@@ -4,6 +4,7 @@
package model
import (
"bufio"
"bytes"
"context"
"encoding/json"
@@ -3696,6 +3697,37 @@ func (c *Client4) GetChannelMembersWithTeamData(ctx context.Context, userID stri
defer closeBody(r)
var ch ChannelMembersWithTeamData
// Check if we need to handle NDJSON format (when page is -1)
if page == -1 {
// Process NDJSON format (each JSON object on new line)
contentType := r.Header.Get("Content-Type")
if contentType == "application/x-ndjson" {
scanner := bufio.NewScanner(r.Body)
ch = ChannelMembersWithTeamData{}
for scanner.Scan() {
line := scanner.Text()
if line == "" {
continue
}
var member ChannelMemberWithTeamData
if err2 := json.Unmarshal([]byte(line), &member); err2 != nil {
return nil, BuildResponse(r), NewAppError("GetChannelMembersWithTeamData", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err2)
}
ch = append(ch, member)
}
if err2 := scanner.Err(); err2 != nil {
return nil, BuildResponse(r), NewAppError("GetChannelMembersWithTeamData", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err2)
}
return ch, BuildResponse(r), nil
}
}
// Standard JSON format
err = json.NewDecoder(r.Body).Decode(&ch)
if err != nil {
return nil, BuildResponse(r), NewAppError("GetChannelMembersWithTeamData", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)