Skip to content

Commit

Permalink
Activities rollup (#45)
Browse files Browse the repository at this point in the history
* Activities rollup

* Adding token_ids aggregation
  • Loading branch information
tifrel authored Jan 3, 2023
1 parent 929d65d commit f655a35
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
table:
schema: mb_views
name: nft_activities_rollup
object_relationships:
- name: nft_contract
using:
manual_configuration:
remote_table:
schema: public
name: nft_contracts
insertion_order: null
column_mapping:
nft_contract_id: id
select_permissions:
- role: anonymous
permission:
columns:
- tx_sender
- timestamp
- nft_contract_id
- kind
- action_sender
- action_receiver
- price
- reference
- reference_blob
- id as metadata_id
- title
- description
- media
- media_hash
- extra
- content_flag
- receipt_id
- count
- token_ids
filter: {}
allow_aggregations: true
2 changes: 2 additions & 0 deletions migrations/2023-01-02-123603_activities-rollup/down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
drop view mb_views.nft_activities_rollup;
drop index nft_activities_receipt_id_index;
65 changes: 65 additions & 0 deletions migrations/2023-01-02-123603_activities-rollup/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
create view mb_views.nft_activities_rollup as
select
a.tx_sender,
a.timestamp,
a.nft_contract_id,
a.kind,
a.action_sender,
a.action_receiver,
a.price,
m.reference,
m.reference_blob,
m.id as metadata_id,
m.title,
m.description,
m.media,
m.media_hash,
m.extra,
m.content_flag,
a.receipt_id,
a.count,
a.token_ids
from (
select
count(*),
tx_sender,
timestamp,
a_.nft_contract_id,
kind,
action_sender,
action_receiver,
price,
receipt_id,
metadata_id,
array_agg(a_.token_id) token_ids
from (
select
a__.nft_contract_id,
a__.token_id,
tx_sender,
timestamp,
kind,
action_sender,
action_receiver,
price,
receipt_id,
metadata_id
from nft_activities a__
left join nft_tokens t
on a__.nft_contract_id = t.nft_contract_id and a__.token_id = t.token_id
) a_
group by
receipt_id,
tx_sender,
timestamp,
nft_contract_id,
kind,
action_sender,
action_receiver,
price,
metadata_id
) a
left join nft_metadata m
on a.metadata_id = m.id;

create index nft_activities_receipt_id_index on nft_activities(receipt_id);

0 comments on commit f655a35

Please sign in to comment.