diff --git a/internal/repository/wallet_repository.go b/internal/repository/wallet_repository.go index a88e269..be3763b 100644 --- a/internal/repository/wallet_repository.go +++ b/internal/repository/wallet_repository.go @@ -188,17 +188,20 @@ func (r *walletRepository) CreateTransaction(ctx context.Context, walletTx *enti } func (r *walletRepository) GetTransactionByIdempotencyKey(ctx context.Context, key string) (*entities.WalletTransaction, error) { - var walletTx entities.WalletTransaction + // Find rather than First: a new key is the normal case, and First would log every + // one of them as a "record not found" error. + var walletTxs []entities.WalletTransaction err := DBFromContext(ctx, r.db).WithContext(ctx). Where("idempotency_key = ?", key). - First(&walletTx).Error + Limit(1). + Find(&walletTxs).Error if err != nil { - if errors.Is(err, gorm.ErrRecordNotFound) { - return nil, nil - } return nil, fmt.Errorf("failed to get wallet transaction by idempotency key: %w", err) } - return &walletTx, nil + if len(walletTxs) == 0 { + return nil, nil + } + return &walletTxs[0], nil } func (r *walletRepository) CreateLot(ctx context.Context, lot *entities.WalletLot) error {