Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⚡ limit the cache queries to some optimal numbers #99

Merged
merged 2 commits into from
Jun 21, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 32 additions & 23 deletions src/mappings/utils/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,46 @@ const STATUS_ID: string = "0"
enum Query {

series = `SELECT
ce.id, ce.name, ce.meta_id as metadata, me.image, ce.issuer,
COUNT(distinct ne.meta_id) as unique,
COUNT(distinct ne.current_owner) as unique_collectors,
COUNT(distinct ne.current_owner) as sold,
COUNT(ne.*) as total,
AVG(ne.price) as average_price,
MIN(NULLIF(ne.price, 0)) as floor_price,
COALESCE(MAX(e.meta :: bigint), 0) as highest_sale,
COALESCE(SUM(e.meta::bigint), 0) as volume,
COUNT(e.*) as buys,
COUNT(em.*) as emote_count
FROM collection_entity ce
ce.id,
ce.name,
ce.meta_id as metadata,
me.image,
ce.issuer,
COUNT(distinct ne.meta_id) as unique,
COUNT(distinct ne.current_owner) as unique_collectors,
COUNT(distinct ne.current_owner) as sold,
COUNT(ne.*) as total,
AVG(ne.price) as average_price,
MIN(NULLIF(ne.price, 0)) as floor_price,
COALESCE(MAX(e.meta :: bigint), 0) as highest_sale,
COALESCE(SUM(e.meta::bigint), 0) as volume,
COUNT(e.*) as buys,
COUNT(em.*) as emote_count
FROM collection_entity ce
LEFT JOIN metadata_entity me on ce.meta_id = me.id
LEFT JOIN nft_entity ne on ce.id = ne.collection_id
LEFT JOIN emote em on ne.id = em.nft_id
JOIN event e on ne.id = e.nft_id
WHERE e.interaction = 'BUY'
GROUP BY ce.id, me.image, ce.name`,
WHERE e.interaction = 'BUY'
GROUP BY ce.id, me.image, ce.name
ORDER BY volume DESC
LIMIT 900`,
Comment on lines +36 to +37
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • default ORDER BY volume DESC?
  • hardcoded 900?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


spotlight = `SELECT
issuer as id,
COUNT(distinct collection_id) as collections,
COUNT(distinct meta_id) as unique,
AVG(price) as average,
COUNT(*) as total,
COUNT(distinct ne.current_owner) as unique_collectors,
issuer as id,
COUNT(distinct collection_id) as collections,
COUNT(distinct meta_id) as unique,
AVG(price) as average,
COUNT(*) as total,
COUNT(distinct ne.current_owner) as unique_collectors,
SUM(CASE WHEN ne.issuer <> ne.current_owner THEN 1 ELSE 0 END) as sold,
COALESCE(SUM(e.meta::bigint), 0) as volume
COALESCE(SUM(e.meta::bigint), 0) as volume
FROM nft_entity ne
JOIN event e on e.nft_id = ne.id WHERE e.interaction = 'BUY'
GROUP BY issuer`,
JOIN event e on e.nft_id = ne.id
WHERE e.interaction = 'BUY'
GROUP BY issuer
ORDER BY sold DESC
LIMIT 360`,
vikiival marked this conversation as resolved.
Show resolved Hide resolved

collector_whale = `SELECT
ne.current_owner as id,
Expand Down