chore: Optimize number of sql calls (#4928)

This commit is contained in:
Cuteivist 2024-03-18 09:37:05 +01:00 committed by GitHub
parent 38183ab335
commit d35a73a94f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 12 additions and 9 deletions

View File

@ -416,18 +416,10 @@ func (r *Reader) getWalletTokenBalances(ctx context.Context, addresses []common.
if !isVisible {
isVisible = balance.Cmp(big.NewFloat(0.0)) > 0 || r.isCachedToken(cachedTokens, address, token.Symbol, token.ChainID)
}
balance1DayAgo, err := r.tokenManager.GetTokenHistoricalBalance(address, token.ChainID, token.Symbol, dayAgoTimestamp)
if err != nil {
return nil, err
}
balance1DayAgoStr := "0"
if balance1DayAgo != nil {
balance1DayAgoStr = balance1DayAgo.String()
}
balancesPerChain[token.ChainID] = ChainBalance{
RawBalance: hexBalance.String(),
Balance: balance,
Balance1DayAgo: balance1DayAgoStr,
Balance1DayAgo: "0",
Address: token.Address,
ChainID: token.ChainID,
HasError: hasError,
@ -438,6 +430,17 @@ func (r *Reader) getWalletTokenBalances(ctx context.Context, addresses []common.
continue
}
for _, balance := range balancesPerChain {
balance1DayAgo, err := r.tokenManager.GetTokenHistoricalBalance(address, balance.ChainID, symbol, dayAgoTimestamp)
if err != nil {
return nil, err
}
if balance1DayAgo != nil {
balance.Balance1DayAgo = balance1DayAgo.String()
balancesPerChain[balance.ChainID] = balance
}
}
walletToken := Token{
Name: tokens[0].Name,
Symbol: symbol,