Skip to content

Commit

Permalink
Invalidate user in cache on user change event (#1604)
Browse files Browse the repository at this point in the history
Co-authored-by: Wim <wim@42.be>
  • Loading branch information
keenan-v1 and 42wim authored Oct 16, 2021
1 parent b56f80b commit b06a574
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions bridge/slack/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ func (b *Bslack) handleSlackClient(messages chan *config.Message) {
b.users.populateUser(ev.User)
case *slack.HelloEvent, *slack.LatencyReport, *slack.ConnectingEvent:
continue
case *slack.UserChangeEvent:
b.users.invalidateUser(ev.User.ID)
default:
b.Log.Debugf("Unhandled incoming event: %T", ev)
}
Expand Down
6 changes: 6 additions & 0 deletions bridge/slack/users_channels.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ func (b *users) populateUser(userID string) {
b.users[userID] = user
}

func (b *users) invalidateUser(userID string) {
b.usersMutex.Lock()
defer b.usersMutex.Unlock()
delete(b.users, userID)
}

func (b *users) populateUsers(wait bool) {
b.refreshMutex.Lock()
if !wait && (time.Now().Before(b.earliestRefresh) || b.refreshInProgress) {
Expand Down

0 comments on commit b06a574

Please sign in to comment.