From 1a1e94c8059edaf4814a2bfdf6e300fc4d87cd9a Mon Sep 17 00:00:00 2001 From: bcmmbaga Date: Thu, 8 May 2025 18:26:46 +0300 Subject: [PATCH] Check account existence without fully loading it Signed-off-by: bcmmbaga --- management/server/account.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/management/server/account.go b/management/server/account.go index b69cebdeb..f3a0e2853 100644 --- a/management/server/account.go +++ b/management/server/account.go @@ -477,19 +477,19 @@ func (am *DefaultAccountManager) newAccount(ctx context.Context, userID, domain for i := 0; i < 2; i++ { accountId := xid.New().String() - _, err := am.Store.GetAccount(ctx, accountId) - statusErr, _ := status.FromError(err) - switch { - case err == nil: - log.WithContext(ctx).Warnf("an account with ID already exists, retrying...") - continue - case statusErr.Type() == status.NotFound: - newAccount := newAccountWithId(ctx, accountId, userID, domain) - am.StoreEvent(ctx, userID, newAccount.Id, accountId, activity.AccountCreated, nil) - return newAccount, nil - default: + exists, err := am.Store.AccountExists(ctx, store.LockingStrengthShare, accountId) + if err != nil { return nil, err } + + if exists { + log.WithContext(ctx).Warnf("an account with ID already exists, retrying...") + continue + } + + newAccount := newAccountWithId(ctx, accountId, userID, domain) + am.StoreEvent(ctx, userID, newAccount.Id, accountId, activity.AccountCreated, nil) + return newAccount, nil } return nil, status.Errorf(status.Internal, "error while creating new account")