summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWim <wim@42.be>2019-04-20 23:06:06 +0200
committerWim <wim@42.be>2019-04-23 23:28:28 +0200
commit1c3e764d572fdb0bc2a371028126a66b376e390e (patch)
tree046f0cf93afce00356c9f64da33b7b6ac9a32a87
parent0b03076a9dd411e567a06f231302f65d95e78c41 (diff)
downloadmatterbridge-msglm-1c3e764d572fdb0bc2a371028126a66b376e390e.tar.gz
matterbridge-msglm-1c3e764d572fdb0bc2a371028126a66b376e390e.tar.bz2
matterbridge-msglm-1c3e764d572fdb0bc2a371028126a66b376e390e.zip
Use paging in initUser and UpdateUsers (mattermost)
-rw-r--r--matterclient/helpers.go19
-rw-r--r--matterclient/users.go21
2 files changed, 31 insertions, 9 deletions
diff --git a/matterclient/helpers.go b/matterclient/helpers.go
index b3d43460..c3d33145 100644
--- a/matterclient/helpers.go
+++ b/matterclient/helpers.go
@@ -132,14 +132,25 @@ func (m *MMClient) initUser() error {
return resp.Error
}
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 {
return errors.New(resp.Error.DetailedError)
}
- usermap := make(map[string]*model.User)
- for _, user := range mmusers {
- usermap[user.Id] = user
+ for len(mmusers) > 0 {
+ for _, user := range mmusers {
+ 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}
diff --git a/matterclient/users.go b/matterclient/users.go
index 11f22aa0..cf13e0df 100644
--- a/matterclient/users.go
+++ b/matterclient/users.go
@@ -2,6 +2,7 @@ package matterclient
import (
"errors"
+ "time"
"github.com/mattermost/mattermost-server/model"
)
@@ -99,15 +100,25 @@ func (m *MMClient) GetUsers() map[string]*model.User {
}
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 {
return errors.New(resp.Error.DetailedError)
}
- m.Lock()
- for _, user := range mmusers {
- m.Users[user.Id] = user
+ for len(mmusers) > 0 {
+ m.Lock()
+ 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
}