Skip to content

Commit

Permalink
[MM-57821] Reduce number of calls to GetUser in syncUsers (#620)
Browse files Browse the repository at this point in the history
  • Loading branch information
JulienTant authored Apr 24, 2024
1 parent 3912d6d commit 187b07f
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions server/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -707,20 +707,23 @@ func (p *Plugin) syncUsers() {
continue
}

user, err := p.API.GetUser(mmUser.Id)
if err != nil {
p.API.LogWarn("Unable to fetch MM user", "user_id", mmUser.Id, "teams_user_id", msUser.ID, "error", err.Error())
continue
}
if configuration.AutomaticallyPromoteSyntheticUsers {
// We need to retrieve the user individually because `GetUsers` does not return AuthData
user, err := p.API.GetUser(mmUser.Id)
if err != nil {
p.API.LogWarn("Unable to fetch MM user", "user_id", mmUser.Id, "teams_user_id", msUser.ID, "error", err.Error())
continue
}

// Update AuthService/AuthData if it changed
if configuration.AutomaticallyPromoteSyntheticUsers && (mmUser.AuthService != configuration.SyntheticUserAuthService || (user.AuthData != nil && authData != "" && *user.AuthData != authData)) {
p.API.LogInfo("Updating user auth service", "user_id", mmUser.Id, "teams_user_id", msUser.ID, "auth_service", configuration.SyntheticUserAuthService)
if _, err := p.API.UpdateUserAuth(mmUser.Id, &model.UserAuth{
AuthService: configuration.SyntheticUserAuthService,
AuthData: &authData,
}); err != nil {
p.API.LogWarn("Unable to update user auth service during sync user job", "user_id", mmUser.Id, "teams_user_id", msUser.ID, "error", err.Error())
// Update AuthService/AuthData if it changed
if mmUser.AuthService != configuration.SyntheticUserAuthService || (user.AuthData != nil && authData != "" && *user.AuthData != authData) {
p.API.LogInfo("Updating user auth service", "user_id", mmUser.Id, "teams_user_id", msUser.ID, "auth_service", configuration.SyntheticUserAuthService)
if _, err := p.API.UpdateUserAuth(mmUser.Id, &model.UserAuth{
AuthService: configuration.SyntheticUserAuthService,
AuthData: &authData,
}); err != nil {
p.API.LogWarn("Unable to update user auth service during sync user job", "user_id", mmUser.Id, "teams_user_id", msUser.ID, "error", err.Error())
}
}
}

Expand Down

0 comments on commit 187b07f

Please sign in to comment.