Skip to content

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusz-sekara committed Aug 16, 2024
1 parent 83eb4b6 commit 2320567
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions core/services/ccip/orm.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ccip
import (
"context"
"fmt"
"strings"
"time"

"github.com/smartcontractkit/chainlink-common/pkg/sqlutil"
Expand Down Expand Up @@ -60,6 +61,7 @@ func (o *orm) GetGasPricesByDestChain(ctx context.Context, destChainSelector uin
FROM ccip.observed_gas_prices
WHERE chain_selector = $1;
`
o.withAnalyze(ctx, "GetGasPricesByDestChain", stmt, destChainSelector)
err := o.ds.SelectContext(ctx, &gasPrices, stmt, destChainSelector)
if err != nil {
return nil, err
Expand All @@ -75,6 +77,7 @@ func (o *orm) GetTokenPricesByDestChain(ctx context.Context, destChainSelector u
FROM ccip.observed_token_prices
WHERE chain_selector = $1;
`
o.withAnalyze(ctx, "GetTokenPricesByDestChain", stmt, destChainSelector)
err := o.ds.SelectContext(ctx, &tokenPrices, stmt, destChainSelector)
if err != nil {
return nil, err
Expand Down Expand Up @@ -166,6 +169,8 @@ func (o *orm) pickOnlyRelevantTokensForUpdate(
WHERE chain_selector = $1 and token_addr = ANY($2);
`

o.withAnalyze(ctx, "pickOnlyRelevantTokensForUpdate", stmt, destChainSelector, tokenAddrsToBytes(tokenPrices))

var dbTokenPrices []tokenPriceRow
if err := o.ds.SelectContext(ctx, &dbTokenPrices, stmt, destChainSelector, tokenAddrsToBytes(tokenPrices)); err != nil {
return nil, err
Expand Down Expand Up @@ -211,3 +216,16 @@ func tokenAddrsToBytes(tokens []TokenPrice) [][]byte {
}
return addrs
}

func (o *orm) withAnalyze(ctx context.Context, queryName string, query string, args ...interface{}) {
query = "EXPLAIN (ANALYZE, BUFFERS) " + query

var response []string
err := o.ds.SelectContext(ctx, &response, query, args...)
if err != nil {
return
}
if len(response) > 0 {
o.lggr.Infow("Analyze query", "query", queryName, "response", strings.Join(response, "\n"))
}
}

0 comments on commit 2320567

Please sign in to comment.