mirror of
https://github.com/cwinfo/matterbridge.git
synced 2024-11-09 16:50:30 +00:00
Use paging in initUser and UpdateUsers (mattermost)
This commit is contained in:
parent
fed77cccf3
commit
9f5f004725
@ -132,14 +132,25 @@ func (m *MMClient) initUser() error {
|
|||||||
return resp.Error
|
return resp.Error
|
||||||
}
|
}
|
||||||
for _, team := range teams {
|
for _, team := range teams {
|
||||||
mmusers, resp := m.Client.GetUsersInTeam(team.Id, 0, 50000, "")
|
idx := 0
|
||||||
|
max := 200
|
||||||
|
usermap := make(map[string]*model.User)
|
||||||
|
mmusers, resp := m.Client.GetUsersInTeam(team.Id, idx, max, "")
|
||||||
if resp.Error != nil {
|
if resp.Error != nil {
|
||||||
return errors.New(resp.Error.DetailedError)
|
return errors.New(resp.Error.DetailedError)
|
||||||
}
|
}
|
||||||
usermap := make(map[string]*model.User)
|
for len(mmusers) > 0 {
|
||||||
for _, user := range mmusers {
|
for _, user := range mmusers {
|
||||||
usermap[user.Id] = user
|
usermap[user.Id] = user
|
||||||
|
}
|
||||||
|
mmusers, resp = m.Client.GetUsersInTeam(team.Id, idx, max, "")
|
||||||
|
if resp.Error != nil {
|
||||||
|
return errors.New(resp.Error.DetailedError)
|
||||||
|
}
|
||||||
|
idx++
|
||||||
|
time.Sleep(time.Millisecond * 200)
|
||||||
}
|
}
|
||||||
|
m.logger.Infof("found %d users in team %s", len(usermap), team.Name)
|
||||||
|
|
||||||
t := &Team{Team: team, Users: usermap, Id: team.Id}
|
t := &Team{Team: team, Users: usermap, Id: team.Id}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package matterclient
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/model"
|
"github.com/mattermost/mattermost-server/model"
|
||||||
)
|
)
|
||||||
@ -99,15 +100,25 @@ func (m *MMClient) GetUsers() map[string]*model.User {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *MMClient) UpdateUsers() error {
|
func (m *MMClient) UpdateUsers() error {
|
||||||
mmusers, resp := m.Client.GetUsers(0, 50000, "")
|
idx := 0
|
||||||
|
max := 200
|
||||||
|
mmusers, resp := m.Client.GetUsers(idx, max, "")
|
||||||
if resp.Error != nil {
|
if resp.Error != nil {
|
||||||
return errors.New(resp.Error.DetailedError)
|
return errors.New(resp.Error.DetailedError)
|
||||||
}
|
}
|
||||||
m.Lock()
|
for len(mmusers) > 0 {
|
||||||
for _, user := range mmusers {
|
m.Lock()
|
||||||
m.Users[user.Id] = user
|
for _, user := range mmusers {
|
||||||
|
m.Users[user.Id] = user
|
||||||
|
}
|
||||||
|
m.Unlock()
|
||||||
|
mmusers, resp = m.Client.GetUsers(idx, max, "")
|
||||||
|
time.Sleep(time.Millisecond * 300)
|
||||||
|
if resp.Error != nil {
|
||||||
|
return errors.New(resp.Error.DetailedError)
|
||||||
|
}
|
||||||
|
idx++
|
||||||
}
|
}
|
||||||
m.Unlock()
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user