mirror of
https://github.com/netbirdio/netbird.git
synced 2026-05-20 23:59:55 +00:00
Check account existence without fully loading it
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
This commit is contained in:
@@ -477,19 +477,19 @@ func (am *DefaultAccountManager) newAccount(ctx context.Context, userID, domain
|
|||||||
for i := 0; i < 2; i++ {
|
for i := 0; i < 2; i++ {
|
||||||
accountId := xid.New().String()
|
accountId := xid.New().String()
|
||||||
|
|
||||||
_, err := am.Store.GetAccount(ctx, accountId)
|
exists, err := am.Store.AccountExists(ctx, store.LockingStrengthShare, accountId)
|
||||||
statusErr, _ := status.FromError(err)
|
if err != nil {
|
||||||
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:
|
|
||||||
return nil, err
|
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")
|
return nil, status.Errorf(status.Internal, "error while creating new account")
|
||||||
|
|||||||
Reference in New Issue
Block a user