debug(accounts): logs temporários de timing em AccountService.List

This commit is contained in:
2026-05-29 00:22:40 -03:00
parent 61981fffcf
commit 4de1af5687
+12
View File
@@ -3,6 +3,8 @@ package service
import ( import (
"context" "context"
"errors" "errors"
"log"
"time"
"financeiro-carvalho/internal/model" "financeiro-carvalho/internal/model"
"financeiro-carvalho/internal/repository" "financeiro-carvalho/internal/repository"
@@ -48,28 +50,36 @@ func (s *AccountService) validate(in model.AccountInput) error {
// List returns accounts, applying CDI yield on-demand and attaching current bill for credit accounts. // List returns accounts, applying CDI yield on-demand and attaching current bill for credit accounts.
func (s *AccountService) List(ctx context.Context) ([]model.Account, error) { func (s *AccountService) List(ctx context.Context) ([]model.Account, error) {
t0 := time.Now()
accounts, err := s.repo.List(ctx) accounts, err := s.repo.List(ctx)
if err != nil { if err != nil {
return nil, err return nil, err
} }
log.Printf("[accounts] repo.List #1: %v", time.Since(t0))
yieldApplied := false yieldApplied := false
for i := range accounts { for i := range accounts {
if accounts[i].YieldType == "cdi" { if accounts[i].YieldType == "cdi" {
tCDI := time.Now()
_ = s.cdiSvc.ApplyYield(ctx, &accounts[i]) _ = s.cdiSvc.ApplyYield(ctx, &accounts[i])
log.Printf("[accounts] ApplyYield account=%d: %v", accounts[i].ID, time.Since(tCDI))
yieldApplied = true yieldApplied = true
} }
} }
if yieldApplied { if yieldApplied {
tList2 := time.Now()
accounts, err = s.repo.List(ctx) accounts, err = s.repo.List(ctx)
if err != nil { if err != nil {
return nil, err return nil, err
} }
log.Printf("[accounts] repo.List #2 (post-yield): %v", time.Since(tList2))
} }
for i := range accounts { for i := range accounts {
if accounts[i].Type == "credit" { if accounts[i].Type == "credit" {
tBill := time.Now()
closing, due := 1, 10 closing, due := 1, 10
if accounts[i].ClosingDay != nil { if accounts[i].ClosingDay != nil {
closing = *accounts[i].ClosingDay closing = *accounts[i].ClosingDay
@@ -80,9 +90,11 @@ func (s *AccountService) List(ctx context.Context) ([]model.Account, error) {
_ = s.billSvc.EnsureCurrentBill(ctx, accounts[i].ID, closing, due) _ = s.billSvc.EnsureCurrentBill(ctx, accounts[i].ID, closing, due)
bill, _ := s.billSvc.GetCurrent(ctx, accounts[i].ID) bill, _ := s.billSvc.GetCurrent(ctx, accounts[i].ID)
accounts[i].CurrentBill = bill accounts[i].CurrentBill = bill
log.Printf("[accounts] EnsureCurrentBill+GetCurrent account=%d: %v", accounts[i].ID, time.Since(tBill))
} }
} }
log.Printf("[accounts] List total: %v", time.Since(t0))
return accounts, nil return accounts, nil
} }