Chore: Remove extra sql select from the Insert function of userimpl.store (#87060)

Remove getAnyUserType
This commit is contained in:
Misi 2024-04-30 08:54:20 +02:00 committed by GitHub
parent 0f4db3f5ad
commit 1cb3f332a1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -75,11 +75,6 @@ func (ss *sqlStore) Insert(ctx context.Context, cmd *user.User) (int64, error) {
return 0, err return 0, err
} }
// verify that user was created and cmd.ID was updated with the actual new userID
_, err = ss.getAnyUserType(ctx, cmd.ID)
if err != nil {
return 0, err
}
return cmd.ID, nil return cmd.ID, nil
} }
@ -588,22 +583,6 @@ func (ss *sqlStore) Search(ctx context.Context, query *user.SearchUsersQuery) (*
return &result, err return &result, err
} }
// getAnyUserType searches for a user record by ID. The user account may be a service account.
func (ss *sqlStore) getAnyUserType(ctx context.Context, userID int64) (*user.User, error) {
usr := user.User{ID: userID}
err := ss.db.WithDbSession(ctx, func(sess *db.Session) error {
has, err := sess.Get(&usr)
if err != nil {
return err
}
if !has {
return user.ErrUserNotFound
}
return nil
})
return &usr, err
}
func setOptional[T any](v *T, add func(v T)) { func setOptional[T any](v *T, add func(v T)) {
if v != nil { if v != nil {
add(*v) add(*v)