debug(accounts): logs temporários de timing em AccountService.List
This commit is contained in:
@@ -3,6 +3,8 @@ package service
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"financeiro-carvalho/internal/model"
|
||||
"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.
|
||||
func (s *AccountService) List(ctx context.Context) ([]model.Account, error) {
|
||||
t0 := time.Now()
|
||||
|
||||
accounts, err := s.repo.List(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
log.Printf("[accounts] repo.List #1: %v", time.Since(t0))
|
||||
|
||||
yieldApplied := false
|
||||
for i := range accounts {
|
||||
if accounts[i].YieldType == "cdi" {
|
||||
tCDI := time.Now()
|
||||
_ = s.cdiSvc.ApplyYield(ctx, &accounts[i])
|
||||
log.Printf("[accounts] ApplyYield account=%d: %v", accounts[i].ID, time.Since(tCDI))
|
||||
yieldApplied = true
|
||||
}
|
||||
}
|
||||
|
||||
if yieldApplied {
|
||||
tList2 := time.Now()
|
||||
accounts, err = s.repo.List(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
log.Printf("[accounts] repo.List #2 (post-yield): %v", time.Since(tList2))
|
||||
}
|
||||
|
||||
for i := range accounts {
|
||||
if accounts[i].Type == "credit" {
|
||||
tBill := time.Now()
|
||||
closing, due := 1, 10
|
||||
if accounts[i].ClosingDay != nil {
|
||||
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)
|
||||
bill, _ := s.billSvc.GetCurrent(ctx, accounts[i].ID)
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user