summaryrefslogtreecommitdiffstats
path: root/matterclient/users.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2019-04-20 23:06:06 +0200
committerWim <wim@42.be>2019-04-20 23:06:06 +0200
commit9f5f0047259f7b28e6e26b762cff853ecacec599 (patch)
treec4dc363d3825c93cc5ca03c4406c0ce4ab4bad3f /matterclient/users.go
parentfed77cccf3ca8104c60ffedbff130a1e520abfb7 (diff)
downloadmatterbridge-msglm-9f5f0047259f7b28e6e26b762cff853ecacec599.tar.gz
matterbridge-msglm-9f5f0047259f7b28e6e26b762cff853ecacec599.tar.bz2
matterbridge-msglm-9f5f0047259f7b28e6e26b762cff853ecacec599.zip
Use paging in initUser and UpdateUsers (mattermost)
Diffstat (limited to 'matterclient/users.go')
-rw-r--r--matterclient/users.go21
1 files changed, 16 insertions, 5 deletions
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
}