Remove db lock on aggregate db calls

Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
This commit is contained in:
bcmmbaga
2024-11-25 21:23:58 +03:00
parent 71af7edd05
commit accada3311
3 changed files with 4 additions and 4 deletions

View File

@@ -1048,7 +1048,7 @@ func BuildManager(
metrics: metrics, metrics: metrics,
requestBuffer: NewAccountRequestBuffer(ctx, store), requestBuffer: NewAccountRequestBuffer(ctx, store),
} }
totalAccounts, err := store.GetTotalAccounts(ctx, LockingStrengthShare) totalAccounts, err := store.GetTotalAccounts(ctx)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@@ -870,9 +870,9 @@ func (s *SqlStore) GetAccountCreatedBy(ctx context.Context, lockStrength Locking
return createdBy, nil return createdBy, nil
} }
func (s *SqlStore) GetTotalAccounts(ctx context.Context, lockStrength LockingStrength) (int64, error) { func (s *SqlStore) GetTotalAccounts(ctx context.Context) (int64, error) {
var count int64 var count int64
result := s.db.Clauses(clause.Locking{Strength: string(lockStrength)}).Model(&Account{}).Count(&count) result := s.db.Model(&Account{}).Count(&count)
if result.Error != nil { if result.Error != nil {
log.WithContext(ctx).Errorf("failed to get total accounts from store: %s", result.Error) log.WithContext(ctx).Errorf("failed to get total accounts from store: %s", result.Error)
return 0, status.Errorf(status.Internal, "failed to get total accounts from store") return 0, status.Errorf(status.Internal, "failed to get total accounts from store")

View File

@@ -58,7 +58,7 @@ type Store interface {
GetAccountSettings(ctx context.Context, lockStrength LockingStrength, accountID string) (*Settings, error) GetAccountSettings(ctx context.Context, lockStrength LockingStrength, accountID string) (*Settings, error)
GetAccountDNSSettings(ctx context.Context, lockStrength LockingStrength, accountID string) (*DNSSettings, error) GetAccountDNSSettings(ctx context.Context, lockStrength LockingStrength, accountID string) (*DNSSettings, error)
GetAccountCreatedBy(ctx context.Context, lockStrength LockingStrength, accountID string) (string, error) GetAccountCreatedBy(ctx context.Context, lockStrength LockingStrength, accountID string) (string, error)
GetTotalAccounts(ctx context.Context, lockStrength LockingStrength) (int64, error) GetTotalAccounts(ctx context.Context) (int64, error)
SaveAccount(ctx context.Context, account *Account) error SaveAccount(ctx context.Context, account *Account) error
DeleteAccount(ctx context.Context, account *Account) error DeleteAccount(ctx context.Context, account *Account) error
UpdateAccountDomainAttributes(ctx context.Context, lockStrength LockingStrength, accountID string, domain string, category string, isPrimaryDomain *bool) error UpdateAccountDomainAttributes(ctx context.Context, lockStrength LockingStrength, accountID string, domain string, category string, isPrimaryDomain *bool) error