Skip to content

Commit

Permalink
Opensea incremental update performance fix (#1451)
Browse files Browse the repository at this point in the history
* Add block_time to fees

* Add block time filter on fees which propagates to traces

* Fix typo
  • Loading branch information
aalan3 authored Aug 29, 2022
1 parent 4ed8d18 commit a6d758e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
2 changes: 2 additions & 0 deletions models/opensea/ethereum/opensea_ethereum_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ models:
tags: ['ethereum','opensea','v1','fees']
description: OpenSea v1 fees on Ethereum
columns:
- name: block_time
description: "Block time of transaction"
- name: trace_address
description: "Trace address for fees"
- name: tx_hash
Expand Down
8 changes: 7 additions & 1 deletion models/opensea/ethereum/opensea_v1_ethereum_events.sql
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,13 @@ SELECT
fees.fee_currency_symbol,
call_trace_address
FROM wyvern_call_data wc
LEFT JOIN {{ ref('opensea_v1_ethereum_fees') }} fees ON fees.tx_hash = wc.call_tx_hash AND fees.trace_address = wc.call_trace_address),
LEFT JOIN {{ ref('opensea_v1_ethereum_fees') }} fees ON
fees.tx_hash = wc.call_tx_hash
AND fees.trace_address = wc.call_trace_address
{% if is_incremental() %}
AND fees.block_time >= date_trunc("day", now() - interval '1 week')
{% endif %}
),

erc_transfers as
(SELECT evt_tx_hash,
Expand Down
14 changes: 9 additions & 5 deletions models/opensea/ethereum/opensea_v1_ethereum_fees.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

{{ config(schema = 'opensea_v1_ethereum',
{{ config(schema = 'opensea_v1_ethereum',
alias='fees') }}

SELECT
block_time,
CASE WHEN size(trace_address) = 1 then array(3::bigint) -- for single row join
WHEN size(trace_address) = 2 then array(trace_address[0])
WHEN size(trace_address) = 3 then array(trace_address[0], trace_address[1])
Expand All @@ -15,9 +15,12 @@ FROM {{ source('ethereum', 'traces') }} source_fees
WHERE
FROM IN ('0x7be8076f4ea4a4ad08075c2508e481d6c946d12b','0x7f268357a8c2552623316e2562d90e642bb538e5')
AND to = '0x5b3256965e7c3cf26e11fcaf296dfc8807c01073' -- OpenSea Wallet
GROUP BY 1,2,4,5
UNION ALL
GROUP BY 1,2,3,5,6

UNION ALL

SELECT
evt_block_time as block_time,
array(3::bigint) as trace_address,
evt_tx_hash as tx_hash,
SUM(value) AS fees,
Expand All @@ -27,4 +30,5 @@ SELECT
LEFT JOIN {{ ref('tokens_ethereum_erc20') }} erc20 ON erc20.contract_address = erc.contract_address
WHERE to = '0x5b3256965e7c3cf26e11fcaf296dfc8807c01073'
AND evt_tx_hash = '0xaa68c271a72a2a280eb06d89506d1feb3de6a84f6f19d1aa001885d783d5b9c7'
GROUP BY 1,2,4,5
GROUP BY 1,2,3,5,6

0 comments on commit a6d758e

Please sign in to comment.