From 19534e88cec60d1adcd9888907fb74785ae44a42 Mon Sep 17 00:00:00 2001 From: Alan Ghobadi Date: Mon, 29 Aug 2022 18:39:06 +0200 Subject: [PATCH] Nft performance 2 (#1449) * Add filter on sudoswap * Add filter on x2y2 * Add filters on looksrare * Add filters on magiceden * Add filters on solana opensea --- models/looksrare/ethereum/looksrare_ethereum_events.sql | 5 ++++- models/magiceden/solana/magiceden_solana_events.sql | 6 +++++- models/opensea/solana/opensea_solana_events.sql | 6 +++++- models/sudoswap/ethereum/sudoswap_ethereum_events.sql | 6 +++--- models/x2y2/ethereum/x2y2_ethereum_events.sql | 5 ++++- 5 files changed, 21 insertions(+), 7 deletions(-) diff --git a/models/looksrare/ethereum/looksrare_ethereum_events.sql b/models/looksrare/ethereum/looksrare_ethereum_events.sql index 00450e19194..23dd89cc554 100644 --- a/models/looksrare/ethereum/looksrare_ethereum_events.sql +++ b/models/looksrare/ethereum/looksrare_ethereum_events.sql @@ -163,7 +163,7 @@ INNER JOIN {{ source('ethereum','transactions') }} tx ON tx_hash = tx.hash AND tx.block_time > '2022-01-01' {% endif %} {% if is_incremental() %} - AND TRY_CAST(date_trunc('DAY', tx.block_time) AS date) = TRY_CAST(date_trunc('DAY', looks_rare.block_time) AS date) + AND tx.block_time >= date_trunc("day", now() - interval '1 week') {% endif %} LEFT JOIN erc_transfers erc ON erc.evt_tx_hash = tx_hash AND erc.token_id_erc = token_id LEFT JOIN {{ ref('tokens_ethereum_nft') }} tokens ON tokens.contract_address = nft_contract_address @@ -171,6 +171,9 @@ LEFT JOIN {{ ref('nft_ethereum_aggregators') }} agg ON agg.contract_address = t LEFT JOIN {{ source('prices', 'usd') }} p ON p.minute = date_trunc('minute', looks_rare.block_time) AND p.contract_address = currency_contract AND p.blockchain ='ethereum' + {% if is_incremental() %} + AND p.minute >= date_trunc("day", now() - interval '1 week') + {% endif %} LEFT JOIN {{ ref('tokens_ethereum_erc20') }} erc20 ON erc20.contract_address = currency_contract WHERE number_of_items >= 1 {% if is_incremental() %} diff --git a/models/magiceden/solana/magiceden_solana_events.sql b/models/magiceden/solana/magiceden_solana_events.sql index ea16533c9e2..99af5c9a918 100644 --- a/models/magiceden/solana/magiceden_solana_events.sql +++ b/models/magiceden/solana/magiceden_solana_events.sql @@ -95,7 +95,11 @@ SELECT FROM {{ source('solana','transactions') }} LEFT JOIN prices.usd p ON p.minute = date_trunc('minute', block_time) + AND p.blockchain is NULL AND p.symbol = 'SOL' + {% if is_incremental() %} + AND p.minute >= date_trunc("day", now() - interval '1 week') + {% endif %} WHERE ( array_contains(account_keys, 'M2mx93ekt1fmXSVkTrUL9xVFHkmME8HTUi5Cyc5aF7K') -- magic eden v2 OR array_contains(account_keys, 'CMZYPASGWeTz7RNGHaRJfCq2XQ5pYK6nDvVQxzkH51zb') @@ -107,5 +111,5 @@ WHERE ( {% endif %} {% if is_incremental() %} -- this filter will only be applied on an incremental run - AND block_date >= (select max(block_date) from {{ this }}) + AND block_date >= date_trunc("day", now() - interval '1 week') {% endif %} \ No newline at end of file diff --git a/models/opensea/solana/opensea_solana_events.sql b/models/opensea/solana/opensea_solana_events.sql index b10076d9cdd..6dbc859f204 100644 --- a/models/opensea/solana/opensea_solana_events.sql +++ b/models/opensea/solana/opensea_solana_events.sql @@ -30,7 +30,11 @@ SELECT FROM {{ source('solana','transactions') }} LEFT JOIN {{ source('prices', 'usd') }} p ON p.minute = date_trunc('minute', block_time) + AND p.blockchain is null AND p.symbol = 'SOL' + {% if is_incremental() %} + AND p.minute >= date_trunc("day", now() - interval '1 week') + {% endif %} WHERE (array_contains(account_keys, '3o9d13qUvEuuauhFrVom1vuCzgNsJifeaBYDPquaT73Y') OR array_contains(account_keys, 'pAHAKoTJsAAe2ZcvTZUxoYzuygVAFAmbYmJYdWT886r')) {% if not is_incremental() %} @@ -38,5 +42,5 @@ AND block_date > '2022-04-06' AND block_slot > 128251864 {% endif %} {% if is_incremental() %} -AND block_date >= (select max(block_date) from {{ this }}) +AND block_date >= date_trunc("day", now() - interval '1 week') {% endif %} \ No newline at end of file diff --git a/models/sudoswap/ethereum/sudoswap_ethereum_events.sql b/models/sudoswap/ethereum/sudoswap_ethereum_events.sql index 91faec41ca9..b737bf7a93f 100644 --- a/models/sudoswap/ethereum/sudoswap_ethereum_events.sql +++ b/models/sudoswap/ethereum/sudoswap_ethereum_events.sql @@ -166,7 +166,7 @@ WITH AND tr.to != '0xb16c1342e617a5b6e4b631eb114483fdb289c0a4' --we don't want duplicates from protocol fee transfer to show up in table. This needs to be most up to date funding recipient in the future, but should just be pair address for now. AND tr.to != asset_recip --we don't want duplicates where eth is transferred to asset recipient instead of pool in the case it isn't a trade pool {% if is_incremental() %} - AND tr.block_time >= (select max(block_time) from {{ this }}) + AND tr.block_time >= date_trunc("day", now() - interval '1 week') {% endif %} {% if not is_incremental() %} AND tr.block_time >= '2022-4-1' @@ -241,7 +241,7 @@ WITH AND date_trunc('minute', pu.minute)=date_trunc('minute', sc.block_time) AND symbol = 'WETH' {% if is_incremental() %} - AND pu.minute >= (select max(block_time) from {{ this }}) + AND pu.minute >= date_trunc("day", now() - interval '1 week') {% endif %} {% if not is_incremental() %} AND pu.minute >= '2022-4-1' @@ -250,7 +250,7 @@ WITH LEFT JOIN {{ source('ethereum', 'transactions') }} tx ON tx.hash=sc.tx_hash {% if is_incremental() %} - AND tx.block_time >= (select max(block_time) from {{ this }}) + AND tx.block_time >= date_trunc("day", now() - interval '1 week') {% endif %} {% if not is_incremental() %} AND tx.block_time >= '2022-4-1' diff --git a/models/x2y2/ethereum/x2y2_ethereum_events.sql b/models/x2y2/ethereum/x2y2_ethereum_events.sql index 4158d91c59f..ebf0485f43c 100644 --- a/models/x2y2/ethereum/x2y2_ethereum_events.sql +++ b/models/x2y2/ethereum/x2y2_ethereum_events.sql @@ -193,9 +193,12 @@ LEFT JOIN {{ source('prices','usd') }} pu ON pu.blockchain='ethereum' AND date_trunc('minute', pu.minute)=date_trunc('minute', txs.block_time) AND (pu.contract_address=txs.currency_contract OR (pu.contract_address='0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2' AND txs.currency_contract='0x0000000000000000000000000000000000000000')) + {% if is_incremental() %} + AND pu.minute >= date_trunc("day", now() - interval '1 week') + {% endif %} LEFT JOIN {{ source('ethereum','transactions') }} et ON et.hash=txs.tx_hash {% if is_incremental() %} - AND TRY_CAST(date_trunc('DAY', et.block_time) AS date) = TRY_CAST(date_trunc('DAY', txs.block_time) AS date) + AND et.block_time >= date_trunc("day", now() - interval '1 week') {% endif %} LEFT JOIN {{ source('erc721_ethereum','evt_transfer') }} erct ON txs.project_contract_address=erct.contract_address AND erct.evt_tx_hash=txs.tx_hash