From 6af97f569606e16702cfe3e9ebbd534be883920e Mon Sep 17 00:00:00 2001 From: efrilm Date: Wed, 30 Sep 2026 08:47:37 +0700 Subject: [PATCH] fix(wallet): stop logging new idempotency keys as errors GetTransactionByIdempotencyKey used First, so every wallet operation with a key not seen before, which is the normal case, logged a "record not found" error. It now uses Find with a limit and returns nil when nothing matches. Co-Authored-By: Claude Opus 5.5 --- internal/repository/wallet_repository.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) 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 {