Skip to content

Commit 978825e

Browse files
committed
Check account existence without fully loading it
Signed-off-by: bcmmbaga <[email protected]>
1 parent ed939bf commit 978825e

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

management/server/account.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -477,13 +477,12 @@ func (am *DefaultAccountManager) newAccount(ctx context.Context, userID, domain
477477
for i := 0; i < 2; i++ {
478478
accountId := xid.New().String()
479479

480-
_, err := am.Store.GetAccount(ctx, accountId)
481-
statusErr, _ := status.FromError(err)
480+
exists, err := am.Store.AccountExists(ctx, store.LockingStrengthShare, accountId)
482481
switch {
483-
case err == nil:
482+
case exists == true:
484483
log.WithContext(ctx).Warnf("an account with ID already exists, retrying...")
485484
continue
486-
case statusErr.Type() == status.NotFound:
485+
case exists == false:
487486
newAccount := newAccountWithId(ctx, accountId, userID, domain)
488487
am.StoreEvent(ctx, userID, newAccount.Id, accountId, activity.AccountCreated, nil)
489488
return newAccount, nil

0 commit comments

Comments
 (0)