Skip to content

Commit

Permalink
Better indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusz-sekara committed Aug 14, 2024
1 parent 94a1364 commit 83eb4b6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
6 changes: 2 additions & 4 deletions core/services/ccip/orm.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ func (o *orm) GetGasPricesByDestChain(ctx context.Context, destChainSelector uin
stmt := `
SELECT source_chain_selector, gas_price
FROM ccip.observed_gas_prices
WHERE chain_selector = $1
ORDER BY source_chain_selector, created_at DESC;
WHERE chain_selector = $1;
`
err := o.ds.SelectContext(ctx, &gasPrices, stmt, destChainSelector)
if err != nil {
Expand All @@ -74,8 +73,7 @@ func (o *orm) GetTokenPricesByDestChain(ctx context.Context, destChainSelector u
stmt := `
SELECT token_addr, token_price
FROM ccip.observed_token_prices
WHERE chain_selector = $1
ORDER BY token_addr;
WHERE chain_selector = $1;
`
err := o.ds.SelectContext(ctx, &tokenPrices, stmt, destChainSelector)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions core/store/migrate/migrations/0249_ccip_token_prices_fix.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ CREATE TABLE ccip.observed_token_prices
token_addr BYTEA NOT NULL,
token_price NUMERIC(78, 0) NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
CONSTRAINT unique_token_chain_selector UNIQUE (token_addr, chain_selector)
PRIMARY KEY (chain_selector, token_addr)
);

CREATE TABLE ccip.observed_gas_prices
Expand All @@ -19,7 +19,7 @@ CREATE TABLE ccip.observed_gas_prices
source_chain_selector NUMERIC(20, 0) NOT NULL,
gas_price NUMERIC(78, 0) NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
CONSTRAINT unique_source_dest_chain UNIQUE (source_chain_selector, chain_selector)
PRIMARY KEY (chain_selector, source_chain_selector)
);

-- +goose Down
Expand Down

0 comments on commit 83eb4b6

Please sign in to comment.