mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
[MM-49243] - Use paged requests to request the list of teams (#26278)
Co-authored-by: Mattermost Build <build@mattermost.com>
This commit is contained in:
parent
087c993bed
commit
4bbcfd74ad
@ -497,7 +497,9 @@ func searchChannelCmdF(c client.Client, cmd *cobra.Command, args []string) error
|
||||
return errors.Errorf("channel %s was not found in team %s", args[0], teamArg)
|
||||
}
|
||||
} else {
|
||||
teams, _, err := c.GetAllTeams(context.TODO(), "", 0, 9999)
|
||||
teams, err := getPages(func(page, numPerPage int, etag string) ([]*model.Team, *model.Response, error) {
|
||||
return c.GetAllTeams(context.TODO(), etag, page, numPerPage)
|
||||
}, DefaultPageSize)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -69,10 +69,16 @@ func (s *MmctlUnitTestSuite) TestSearchChannelCmdF() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetAllTeams(context.TODO(), "", 0, 9999).
|
||||
GetAllTeams(context.TODO(), "", 0, DefaultPageSize).
|
||||
Return(mockTeams, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetAllTeams(context.TODO(), "", 1, DefaultPageSize).
|
||||
Return([]*model.Team{}, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
// first call is for the other team, that doesn't have the channel
|
||||
s.client.
|
||||
EXPECT().
|
||||
|
@ -188,7 +188,9 @@ func createCommandCmdF(c client.Client, cmd *cobra.Command, args []string) error
|
||||
func listCommandCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
||||
var teams []*model.Team
|
||||
if len(args) < 1 {
|
||||
teamList, _, err := c.GetAllTeams(context.TODO(), "", 0, 10000)
|
||||
teamList, err := getPages(func(page, numPerPage int, etag string) ([]*model.Team, *model.Response, error) {
|
||||
return c.GetAllTeams(context.TODO(), etag, page, numPerPage)
|
||||
}, DefaultPageSize)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -417,7 +417,8 @@ func (s *MmctlUnitTestSuite) TestCommandListCmdF() {
|
||||
}
|
||||
|
||||
cmd := &cobra.Command{}
|
||||
s.client.EXPECT().GetAllTeams(context.TODO(), "", 0, 10000).Return(teams, &model.Response{}, nil).Times(1)
|
||||
s.client.EXPECT().GetAllTeams(context.TODO(), "", 0, DefaultPageSize).Return(teams, &model.Response{}, nil).Times(1)
|
||||
s.client.EXPECT().GetAllTeams(context.TODO(), "", 1, DefaultPageSize).Return([]*model.Team{}, &model.Response{}, nil).Times(1)
|
||||
s.client.EXPECT().ListCommands(context.TODO(), team1ID, true).Return(team1Commands, &model.Response{}, nil).Times(1)
|
||||
s.client.EXPECT().ListCommands(context.TODO(), team2Id, true).Return(team2Commands, &model.Response{}, nil).Times(1)
|
||||
err := listCommandCmdF(s.client, cmd, []string{})
|
||||
|
@ -396,7 +396,7 @@ func importValidateCmdF(command *cobra.Command, args []string) error {
|
||||
err := withClient(func(c client.Client, cmd *cobra.Command, args []string) error {
|
||||
users, err := getPages(func(page, numPerPage int, etag string) ([]*model.User, *model.Response, error) {
|
||||
return c.GetUsers(context.TODO(), page, numPerPage, etag)
|
||||
}, 250)
|
||||
}, DefaultPageSize)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -410,7 +410,7 @@ func importValidateCmdF(command *cobra.Command, args []string) error {
|
||||
|
||||
teams, err := getPages(func(page, numPerPage int, etag string) ([]*model.Team, *model.Response, error) {
|
||||
return c.GetAllTeams(context.TODO(), etag, page, numPerPage)
|
||||
}, 250)
|
||||
}, DefaultPageSize)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -421,14 +421,14 @@ func importValidateCmdF(command *cobra.Command, args []string) error {
|
||||
|
||||
publicChannels, err := getPages(func(page, numPerPage int, etag string) ([]*model.Channel, *model.Response, error) {
|
||||
return c.GetPublicChannelsForTeam(context.TODO(), team.Id, page, numPerPage, etag)
|
||||
}, 250)
|
||||
}, DefaultPageSize)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
privateChannels, err := getPages(func(page, numPerPage int, etag string) ([]*model.Channel, *model.Response, error) {
|
||||
return c.GetPrivateChannelsForTeam(context.TODO(), team.Id, page, numPerPage, etag)
|
||||
}, 250)
|
||||
}, DefaultPageSize)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -14,6 +14,8 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
const DefaultPageSize = 200
|
||||
|
||||
func checkInteractiveTerminal() error {
|
||||
fileInfo, err := os.Stdout.Stat()
|
||||
if err != nil {
|
||||
|
@ -92,7 +92,9 @@ func listWebhookCmdF(c client.Client, command *cobra.Command, args []string) err
|
||||
if len(args) < 1 {
|
||||
var err error
|
||||
// If no team is specified, list all teams
|
||||
teams, _, err = c.GetAllTeams(context.TODO(), "", 0, 100000000)
|
||||
teams, err = getPages(func(page, numPerPage int, etag string) ([]*model.Team, *model.Response, error) {
|
||||
return c.GetAllTeams(context.TODO(), etag, page, numPerPage)
|
||||
}, DefaultPageSize)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -40,10 +40,16 @@ func (s *MmctlUnitTestSuite) TestListWebhookCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetAllTeams(context.TODO(), "", 0, 100000000).
|
||||
GetAllTeams(context.TODO(), "", 0, DefaultPageSize).
|
||||
Return([]*model.Team{&mockTeam}, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetAllTeams(context.TODO(), "", 1, DefaultPageSize).
|
||||
Return([]*model.Team{}, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetIncomingWebhooksForTeam(context.TODO(), teamID, 0, 100000000, "").
|
||||
@ -114,10 +120,16 @@ func (s *MmctlUnitTestSuite) TestListWebhookCmd() {
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetAllTeams(context.TODO(), "", 0, 100000000).
|
||||
GetAllTeams(context.TODO(), "", 0, DefaultPageSize).
|
||||
Return([]*model.Team{&mockTeam}, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetAllTeams(context.TODO(), "", 1, DefaultPageSize).
|
||||
Return([]*model.Team{}, &model.Response{}, nil).
|
||||
Times(1)
|
||||
|
||||
s.client.
|
||||
EXPECT().
|
||||
GetIncomingWebhooksForTeam(context.TODO(), teamID, 0, 100000000, "").
|
||||
|
Loading…
Reference in New Issue
Block a user