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

Speed up community tokens query for contract communities #1348

Merged
merged 1 commit into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
51 changes: 19 additions & 32 deletions db/gen/coredb/batch.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 34 additions & 29 deletions db/gen/coredb/community.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions db/gen/coredb/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -87144,7 +87144,7 @@
"insert_into_table": null
},
{
"text": "with community_data as (\n select community_type, contract_id\n from communities\n where communities.id = $1 and not deleted\n),\n\ncontract_memberships as (\n select tokens.id\n from community_data, tokens\n where community_data.community_type = 0\n and tokens.contract_id = community_data.contract_id\n and not tokens.deleted\n),\n\ntoken_memberships as (\n select tokens.id\n from community_data, tokens\n join token_community_memberships on tokens.token_definition_id = token_community_memberships.token_definition_id\n and token_community_memberships.community_id = $1\n and not token_community_memberships.deleted\n where community_data.community_type != 0\n and not tokens.deleted\n)\n\n(select t.id, t.deleted, t.version, t.created_at, t.last_updated, t.collectors_note, t.quantity, t.block_number, t.owner_user_id, t.owned_by_wallets, t.contract_id, t.is_user_marked_spam, t.last_synced, t.is_creator_token, t.token_definition_id, t.is_holder_token, t.displayable, td.id, td.created_at, td.last_updated, td.deleted, td.name, td.description, td.token_type, td.token_id, td.external_url, td.chain, td.metadata, td.fallback_media, td.contract_address, td.contract_id, td.token_media_id, td.is_fxhash, c.id, c.deleted, c.version, c.created_at, c.last_updated, c.name, c.symbol, c.address, c.creator_address, c.chain, c.profile_banner_url, c.profile_image_url, c.badge_url, c.description, c.owner_address, c.is_provider_marked_spam, c.parent_id, c.override_creator_user_id, c.l1_chain from contract_memberships ct\n join tokens t on t.id = ct.id\n join token_definitions td on t.token_definition_id = td.id\n join users u on u.id = t.owner_user_id\n join contracts c on t.contract_id = c.id\n where t.displayable\n and t.deleted = false\n and c.deleted = false\n and td.deleted = false\n and u.deleted = false\n and u.universal = false\n and (t.created_at,t.id) \u003c ($2::timestamptz, $3)\n and (t.created_at,t.id) \u003e ($4::timestamptz, $5)\n order by case when $6::bool then (t.created_at,t.id) end asc,\n case when not $6::bool then (t.created_at,t.id) end desc\n limit $7)\n\nunion all\n\n(select t.id, t.deleted, t.version, t.created_at, t.last_updated, t.collectors_note, t.quantity, t.block_number, t.owner_user_id, t.owned_by_wallets, t.contract_id, t.is_user_marked_spam, t.last_synced, t.is_creator_token, t.token_definition_id, t.is_holder_token, t.displayable, td.id, td.created_at, td.last_updated, td.deleted, td.name, td.description, td.token_type, td.token_id, td.external_url, td.chain, td.metadata, td.fallback_media, td.contract_address, td.contract_id, td.token_media_id, td.is_fxhash, c.id, c.deleted, c.version, c.created_at, c.last_updated, c.name, c.symbol, c.address, c.creator_address, c.chain, c.profile_banner_url, c.profile_image_url, c.badge_url, c.description, c.owner_address, c.is_provider_marked_spam, c.parent_id, c.override_creator_user_id, c.l1_chain from token_memberships ct\n join tokens t on t.id = ct.id\n join token_definitions td on t.token_definition_id = td.id\n join users u on u.id = t.owner_user_id\n join contracts c on t.contract_id = c.id\n where t.displayable\n and t.deleted = false\n and c.deleted = false\n and td.deleted = false\n and u.deleted = false\n and u.universal = false\n and (t.created_at,t.id) \u003c ($2::timestamptz, $3)\n and (t.created_at,t.id) \u003e ($4::timestamptz, $5)\n order by case when $6::bool then (t.created_at,t.id) end asc,\n case when not $6::bool then (t.created_at,t.id) end desc\n limit $7)",
"text": "with community_data as (\n select id as community_id, community_type, contract_id\n from communities\n where communities.id = $1 and not deleted\n limit 1\n)\n\n(select t.id, t.deleted, t.version, t.created_at, t.last_updated, t.collectors_note, t.quantity, t.block_number, t.owner_user_id, t.owned_by_wallets, t.contract_id, t.is_user_marked_spam, t.last_synced, t.is_creator_token, t.token_definition_id, t.is_holder_token, t.displayable, td.id, td.created_at, td.last_updated, td.deleted, td.name, td.description, td.token_type, td.token_id, td.external_url, td.chain, td.metadata, td.fallback_media, td.contract_address, td.contract_id, td.token_media_id, td.is_fxhash, c.id, c.deleted, c.version, c.created_at, c.last_updated, c.name, c.symbol, c.address, c.creator_address, c.chain, c.profile_banner_url, c.profile_image_url, c.badge_url, c.description, c.owner_address, c.is_provider_marked_spam, c.parent_id, c.override_creator_user_id, c.l1_chain from community_data cd\n join tokens t on t.contract_id = cd.contract_id\n join token_definitions td on t.token_definition_id = td.id\n join users u on u.id = t.owner_user_id\n join contracts c on t.contract_id = c.id\nwhere cd.community_type = 0\n and t.displayable\n and t.deleted = false\n and c.deleted = false\n and td.deleted = false\n and u.deleted = false\n and u.universal = false\n and (t.created_at,t.id) \u003c ($2::timestamptz, $3)\n and (t.created_at,t.id) \u003e ($4::timestamptz, $5)\norder by case when $6::bool then (t.created_at,t.id) end asc,\n case when not $6::bool then (t.created_at,t.id) end desc\nlimit $7)\n\nunion all\n\n(select t.id, t.deleted, t.version, t.created_at, t.last_updated, t.collectors_note, t.quantity, t.block_number, t.owner_user_id, t.owned_by_wallets, t.contract_id, t.is_user_marked_spam, t.last_synced, t.is_creator_token, t.token_definition_id, t.is_holder_token, t.displayable, td.id, td.created_at, td.last_updated, td.deleted, td.name, td.description, td.token_type, td.token_id, td.external_url, td.chain, td.metadata, td.fallback_media, td.contract_address, td.contract_id, td.token_media_id, td.is_fxhash, c.id, c.deleted, c.version, c.created_at, c.last_updated, c.name, c.symbol, c.address, c.creator_address, c.chain, c.profile_banner_url, c.profile_image_url, c.badge_url, c.description, c.owner_address, c.is_provider_marked_spam, c.parent_id, c.override_creator_user_id, c.l1_chain from community_data cd, token_community_memberships tcm\n join tokens t on t.token_definition_id = tcm.token_definition_id\n join token_definitions td on td.id = t.token_definition_id\n join users u on u.id = t.owner_user_id\n join contracts c on t.contract_id = c.id\nwhere cd.community_type != 0\n and tcm.community_id = cd.community_id\n and t.displayable\n and tcm.deleted = false\n and t.deleted = false\n and c.deleted = false\n and td.deleted = false\n and u.deleted = false\n and u.universal = false\n and (t.created_at,t.id) \u003c ($2::timestamptz, $3)\n and (t.created_at,t.id) \u003e ($4::timestamptz, $5)\norder by case when $6::bool then (t.created_at,t.id) end asc,\n case when not $6::bool then (t.created_at,t.id) end desc\nlimit $7)",
"name": "PaginateTokensByCommunityID",
"cmd": ":batchmany",
"columns": [
Expand Down Expand Up @@ -87429,12 +87429,12 @@
"insert_into_table": null
},
{
"text": "with community_data as (\n select community_type, contract_id\n from communities\n where communities.id = $1 and not deleted\n),\n\ncommunity_tokens as (\n select tokens.id, tokens.deleted, tokens.version, tokens.created_at, tokens.last_updated, tokens.collectors_note, tokens.quantity, tokens.block_number, tokens.owner_user_id, tokens.owned_by_wallets, tokens.contract_id, tokens.is_user_marked_spam, tokens.last_synced, tokens.is_creator_token, tokens.token_definition_id, tokens.is_holder_token, tokens.displayable\n from community_data, tokens\n where community_data.community_type = 0\n and tokens.contract_id = community_data.contract_id\n and not tokens.deleted\n\n union all\n\n select tokens.id, tokens.deleted, tokens.version, tokens.created_at, tokens.last_updated, tokens.collectors_note, tokens.quantity, tokens.block_number, tokens.owner_user_id, tokens.owned_by_wallets, tokens.contract_id, tokens.is_user_marked_spam, tokens.last_synced, tokens.is_creator_token, tokens.token_definition_id, tokens.is_holder_token, tokens.displayable\n from community_data, tokens\n join token_community_memberships on tokens.token_definition_id = token_community_memberships.token_definition_id\n and token_community_memberships.community_id = $1\n and not token_community_memberships.deleted\n where community_data.community_type != 0\n and not tokens.deleted\n)\n\nselect count(t.*) from community_tokens t\n join token_definitions td on t.token_definition_id = td.id\n join users u on u.id = t.owner_user_id\n join contracts c on t.contract_id = c.id\n where t.displayable\n and t.deleted = false\n and c.deleted = false\n and td.deleted = false\n and u.universal = false",
"text": "with community_data as (\n select id as community_id, community_type, contract_id\n from communities\n where communities.id = $1 and not deleted\n limit 1\n)\n\nselect sum(u.count) from (\n (select count(t.*) from community_data cd\n join tokens t on t.contract_id = cd.contract_id\n join token_definitions td on t.token_definition_id = td.id\n join users u on u.id = t.owner_user_id\n join contracts c on t.contract_id = c.id\n where cd.community_type = 0\n and t.displayable\n and t.deleted = false\n and c.deleted = false\n and td.deleted = false\n and u.deleted = false\n and u.universal = false)\n\n union all\n\n (select count(t.*) from community_data cd, token_community_memberships tcm\n join tokens t on t.token_definition_id = tcm.token_definition_id\n join token_definitions td on td.id = t.token_definition_id\n join users u on u.id = t.owner_user_id\n join contracts c on t.contract_id = c.id\n where cd.community_type != 0\n and tcm.community_id = cd.community_id\n and t.displayable\n and tcm.deleted = false\n and t.deleted = false\n and c.deleted = false\n and td.deleted = false\n and u.deleted = false\n and u.universal = false)\n) u",
"name": "CountTokensByCommunityID",
"cmd": ":one",
"columns": [
{
"name": "count",
"name": "sum",
"not_null": true,
"is_array": false,
"comment": "",
Expand Down
Loading
Loading