Skip to content

Commit

Permalink
fix: casting slowing down queries
Browse files Browse the repository at this point in the history
  • Loading branch information
juanmahidalgo committed Dec 11, 2024
1 parent d9f0b0d commit ebaa7ed
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/ports/catalog/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ const getTradesCTE = () => {
)
) AS assets,
CASE
WHEN COUNT(CASE WHEN trade_status.action = 'cancelled' THEN 1 END) > 0 THEN '${ListingStatus.CANCELLED}'
WHEN COUNT(CASE WHEN trade_status.action = 'cancelled' THEN 1 END) > 0 THEN 'cancelled'
WHEN t.expires_at < now()::timestamptz(3) THEN '${ListingStatus.CANCELLED}'
WHEN (
(signer_signature_index.index IS NOT NULL AND signer_signature_index.index != (t.checks ->> 'signerSignatureIndex')::int)
Expand Down Expand Up @@ -604,7 +604,7 @@ const getTradesJoin = () => {
FROM unified_trades
WHERE status = 'open'
GROUP BY contract_address_sent, assets -> 'sent' ->> 'item_id'
) AS offchain_orders ON offchain_orders.contract_address_sent = items.collection_id AND offchain_orders.item_id = items.blockchain_id::text
) AS offchain_orders ON offchain_orders.contract_address_sent = items.collection_id AND offchain_orders.item_id::numeric = items.blockchain_id
`
}

Expand Down
3 changes: 2 additions & 1 deletion src/ports/nfts/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ export function createNFTsComponent(components: Pick<AppComponents, 'dappsDataba
if ((error as Error).message === 'Query read timeout') {
console.error('Query timeout exceeded (2 minutes)', {
filters,
query
query: query?.text,
values: query?.values
})
}
throw new HttpError("Couldn't fetch nfts with the filters provided", 400)
Expand Down
4 changes: 2 additions & 2 deletions src/ports/nfts/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ function getTradesCTE(filters: GetNFTsFilters): SQLStatement {
LEFT JOIN marketplace.trade_assets_erc721 as erc721_asset ON ta.id = erc721_asset.asset_id
LEFT JOIN marketplace.trade_assets_erc20 as erc20_asset ON ta.id = erc20_asset.asset_id
LEFT JOIN marketplace.trade_assets_item as item_asset ON ta.id = item_asset.asset_id
LEFT JOIN squid_marketplace.item as item ON (ta.contract_address = item.collection_id AND item_asset.item_id = item.blockchain_id::text)
LEFT JOIN squid_marketplace.item as item ON (ta.contract_address = item.collection_id AND item_asset.item_id::numeric = item.blockchain_id)
LEFT JOIN squid_marketplace.nft as nft ON (ta.contract_address = nft.contract_address AND erc721_asset.token_id::numeric = nft.token_id)
LEFT JOIN squid_marketplace.account as account ON (account.id = nft.owner_id)
) as assets_with_values ON t.id = assets_with_values.trade_id
Expand Down Expand Up @@ -555,7 +555,7 @@ function getRecentlyListedNFTsCTE(nftFilters: GetNFTsFilters): SQLStatement {
LEFT JOIN marketplace.trade_assets_erc721 erc721_asset ON ta.id = erc721_asset.asset_id
LEFT JOIN squid_marketplace.nft nft ON (
ta.contract_address = nft.contract_address
AND erc721_asset.token_id = nft.token_id::TEXT
AND erc721_asset.token_id::numeric = nft.token_id
)
`
.append(whereClauseForTradeNFTsIds)
Expand Down
8 changes: 4 additions & 4 deletions src/ports/trades/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ export function getTradesForTypeQuery(type: TradeType) {
LEFT JOIN marketplace.trade_assets_erc721 as erc721_asset ON ta.id = erc721_asset.asset_id
LEFT JOIN marketplace.trade_assets_erc20 as erc20_asset ON ta.id = erc20_asset.asset_id
LEFT JOIN marketplace.trade_assets_item as item_asset ON ta.id = item_asset.asset_id
LEFT JOIN squid_marketplace.item as item ON (ta.contract_address = item.collection_id AND item_asset.item_id = item.blockchain_id::text)
LEFT JOIN squid_marketplace.nft as nft ON (ta.contract_address = nft.contract_address AND erc721_asset.token_id = nft.token_id::text)
LEFT JOIN squid_marketplace.item as item ON (ta.contract_address = item.collection_id AND item_asset.item_id::numeric = item.blockchain_id)
LEFT JOIN squid_marketplace.nft as nft ON (ta.contract_address = nft.contract_address AND erc721_asset.token_id::numeric = nft.token_id)
LEFT JOIN squid_marketplace.account as account ON (account.id = nft.owner_id)
) as assets_with_values ON t.id = assets_with_values.trade_id
LEFT JOIN squid_trades.trade as trade_status ON trade_status.signature = t.hashed_signature
Expand Down Expand Up @@ -231,8 +231,8 @@ export function getTradesForTypeQueryWithFilters(type: TradeType, filters: NFTFi
LEFT JOIN marketplace.trade_assets_erc721 as erc721_asset ON ta.id = erc721_asset.asset_id
LEFT JOIN marketplace.trade_assets_erc20 as erc20_asset ON ta.id = erc20_asset.asset_id
LEFT JOIN marketplace.trade_assets_item as item_asset ON ta.id = item_asset.asset_id
LEFT JOIN squid_marketplace.item as item ON (ta.contract_address = item.collection_id AND item_asset.item_id = item.blockchain_id::text)
LEFT JOIN squid_marketplace.nft as nft ON (ta.contract_address = nft.contract_address AND erc721_asset.token_id = nft.token_id::text)
LEFT JOIN squid_marketplace.item as item ON (ta.contract_address = item.collection_id AND item_asset.item_id::numeric = item.blockchain_id)
LEFT JOIN squid_marketplace.nft as nft ON (ta.contract_address = nft.contract_address AND erc721_asset.token_id::numeric = nft.token_id)
LEFT JOIN squid_marketplace.account as account ON (account.id = nft.owner_id)
) as assets_with_values ON t.id = assets_with_values.trade_id
LEFT JOIN squid_trades.trade as trade_status ON trade_status.signature = t.hashed_signature
Expand Down

0 comments on commit ebaa7ed

Please sign in to comment.