Skip to content

Commit

Permalink
Merge pull request #195 from decentraland/fix/recently-sale-nfts-query
Browse files Browse the repository at this point in the history
feat: improve nfts by recently listed query performance
  • Loading branch information
juanmahidalgo authored Dec 10, 2024
2 parents 12ad595 + 6b3e7a3 commit d07200a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<AppComponents> {
Expand All @@ -51,7 +51,7 @@ export async function initComponents(): Promise<AppComponents> {
const server = await createServerComponent<GlobalContext>({ 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
})

Expand Down
19 changes: 14 additions & 5 deletions src/ports/nfts/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit d07200a

Please sign in to comment.