Skip to content

Commit

Permalink
Fetch account user info once for bulk users save
Browse files Browse the repository at this point in the history
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
  • Loading branch information
bcmmbaga committed Feb 13, 2025
1 parent 7b0238e commit 31917e6
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions management/server/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,10 +536,16 @@ func (am *DefaultAccountManager) SaveOrAddUsers(ctx context.Context, accountID,
}

var updatedUsersInfo = make([]*types.UserInfo, 0, len(updates))

userInfos, err := am.GetUsersFromAccount(ctx, accountID, initiatorUserID)
if err != nil {
return nil, err
}

for _, updatedUser := range usersToSave {
updatedUserInfo, err := am.getUserInfo(ctx, updatedUser, accountID)
if err != nil {
return nil, fmt.Errorf("failed to get user info: %w", err)
updatedUserInfo, ok := userInfos[updatedUser.Id]
if !ok || updatedUserInfo == nil {
return nil, fmt.Errorf("failed to get user: %s updated user info", updatedUser.Id)
}
updatedUsersInfo = append(updatedUsersInfo, updatedUserInfo)
}
Expand Down

0 comments on commit 31917e6

Please sign in to comment.