From 6b3e7a3d25a35d1d3cda363a0a526b8dc2176cb0 Mon Sep 17 00:00:00 2001 From: Juanma Hidalgo Date: Tue, 10 Dec 2024 14:40:09 +0100 Subject: [PATCH] feat: improve nfts by recently listed query performance --- src/components.ts | 4 ++-- src/ports/nfts/queries.ts | 19 ++++++++++++++----- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/components.ts b/src/components.ts index 98175ac..d396e07 100644 --- a/src/components.ts +++ b/src/components.ts @@ -35,7 +35,7 @@ import { createWertSigner } from './ports/wert-signer/component' import { AppComponents, GlobalContext } from './types' const thirtySeconds = 30 * 1000 -const fiveMinutes = 5 * 60 * 1000 +const fifteenMinutes = 15 * 60 * 1000 // Initialize all the components of the app export async function initComponents(): Promise { @@ -51,7 +51,7 @@ export async function initComponents(): Promise { const server = await createServerComponent({ config, logs }, { cors }) const statusChecks = await createStatusCheckComponent({ server, config }) const fetch = await createFetchComponent({ tracer }) - const updateBuilderServerItemsViewJob = createJobComponent({ logs }, () => catalog.updateBuilderServerItemsView(), fiveMinutes, { + const updateBuilderServerItemsViewJob = createJobComponent({ logs }, () => catalog.updateBuilderServerItemsView(), fifteenMinutes, { startupDelay: thirtySeconds }) diff --git a/src/ports/nfts/queries.ts b/src/ports/nfts/queries.ts index 98e78ed..8c1dd13 100644 --- a/src/ports/nfts/queries.ts +++ b/src/ports/nfts/queries.ts @@ -219,7 +219,7 @@ function getTradesCTE(): SQLStatement { 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.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 @@ -565,12 +565,21 @@ function getRecentlyListedNFTsCTE(nftFilters: GetNFTsFilters): SQLStatement { .append( SQL` ), + filtered_orders AS ( + SELECT nft_id + FROM squid_marketplace."order" + WHERE status = 'open' AND expires_normalized > NOW() + ORDER BY expires_normalized DESC NULLS LAST + LIMIT 24 + ), nfts_with_orders AS ( - SELECT *, - NULL::timestamp AS trade_created_at, - NULL::json AS trade_assets, - 'order' AS reason + SELECT + nft.*, + NULL::timestamp AS trade_created_at, + NULL::json AS trade_assets, + 'order' AS reason FROM squid_marketplace.nft + JOIN filtered_orders ON nft.id = filtered_orders.nft_id ` .append(whereClauseForNFTsWithOrders) .append(