diff options
author | Wim <wim@42.be> | 2018-12-15 23:11:03 +0100 |
---|---|---|
committer | Wim <wim@42.be> | 2018-12-15 23:21:31 +0100 |
commit | 859b084814f179345866d98d9c01117a204f6839 (patch) | |
tree | deb6ad05ebc3aeefb4b8b1930dac0c1cc1f3e944 /bridge/slack/helpers.go | |
parent | 315a038e001ead142e93eb104bd71d062a0391a2 (diff) | |
download | matterbridge-msglm-859b084814f179345866d98d9c01117a204f6839.tar.gz matterbridge-msglm-859b084814f179345866d98d9c01117a204f6839.tar.bz2 matterbridge-msglm-859b084814f179345866d98d9c01117a204f6839.zip |
Add wait option for populateUsers/Channels (slack) Fixes #579 (#653)
When setting wait to true, we wait until the populating isn't in progress anymore.
This is used on startup connections where we really need the initial information
which could take a long time on big servers.
Diffstat (limited to 'bridge/slack/helpers.go')
-rw-r--r-- | bridge/slack/helpers.go | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/bridge/slack/helpers.go b/bridge/slack/helpers.go index a03feb7b..bf9a3257 100644 --- a/bridge/slack/helpers.go +++ b/bridge/slack/helpers.go @@ -85,15 +85,18 @@ func (b *Bslack) populateUser(userID string) { b.usersMutex.Unlock() } -func (b *Bslack) populateUsers() { +func (b *Bslack) populateUsers(wait bool) { b.refreshMutex.Lock() - if time.Now().Before(b.earliestUserRefresh) || b.refreshInProgress { + if !wait && (time.Now().Before(b.earliestUserRefresh) || b.refreshInProgress) { b.Log.Debugf("Not refreshing user list as it was done less than %v ago.", minimumRefreshInterval) b.refreshMutex.Unlock() return } + for b.refreshInProgress { + time.Sleep(time.Second) + } b.refreshInProgress = true b.refreshMutex.Unlock() @@ -129,14 +132,17 @@ func (b *Bslack) populateUsers() { b.refreshInProgress = false } -func (b *Bslack) populateChannels() { +func (b *Bslack) populateChannels(wait bool) { b.refreshMutex.Lock() - if time.Now().Before(b.earliestChannelRefresh) || b.refreshInProgress { + if !wait && (time.Now().Before(b.earliestChannelRefresh) || b.refreshInProgress) { b.Log.Debugf("Not refreshing channel list as it was done less than %v seconds ago.", minimumRefreshInterval) b.refreshMutex.Unlock() return } + for b.refreshInProgress { + time.Sleep(time.Second) + } b.refreshInProgress = true b.refreshMutex.Unlock() |