From 7935af2ee448668dad9f995a85f2cd42cae53e6e Mon Sep 17 00:00:00 2001 From: Jake Naviasky Date: Wed, 7 Aug 2024 14:45:55 -0400 Subject: [PATCH] Always return stake and tag data. --- .../src/community/GetCommunities.query.ts | 59 ++++++------------- 1 file changed, 18 insertions(+), 41 deletions(-) diff --git a/libs/model/src/community/GetCommunities.query.ts b/libs/model/src/community/GetCommunities.query.ts index 9244a6a20e3..3d72a7b9190 100644 --- a/libs/model/src/community/GetCommunities.query.ts +++ b/libs/model/src/community/GetCommunities.query.ts @@ -36,7 +36,18 @@ export function GetCommunities(): Query { const replacements = filtering_tags ? { tag_ids } : {}; const sql = ` - SELECT DISTINCT ON ("Community"."id", "Community"."${order_col}") "Community".*, count(*) OVER() AS total + SELECT DISTINCT ON ("Community"."id", "Community"."${order_col}") "Community".*, count(*) OVER() AS total, + "CommunityTags"."community_id" AS "CommunityTags.community_id", + "CommunityTags"."tag_id" AS "CommunityTags.tag_id", + "CommunityTags->Tag"."id" AS "CommunityTags.Tag.id", + "CommunityTags->Tag"."name" AS "CommunityTags.Tag.name", + "CommunityStakes"."community_id" AS "CommunityStakes.community_id", + "CommunityStakes"."stake_id" AS "CommunityStakes.stake_id", + "CommunityStakes"."stake_token" AS "CommunityStakes.stake_token", + "CommunityStakes"."vote_weight" AS "CommunityStakes.vote_weight", + "CommunityStakes"."stake_enabled" AS "CommunityStakes.stake_enabled", + "CommunityStakes"."created_at" AS "CommunityStakes.created_at", + "CommunityStakes"."updated_at" AS "CommunityStakes.updated_at" ${ has_groups ? ` @@ -50,27 +61,6 @@ export function GetCommunities(): Query { ` : '' } - ${ - filtering_tags - ? ` - , "CommunityTags"."community_id" AS "CommunityTags.community_id", - "CommunityTags"."tag_id" AS "CommunityTags.tag_id", - "CommunityTags->Tag"."id" AS "CommunityTags.Tag.id", - "CommunityTags->Tag"."name" AS "CommunityTags.Tag.name"` - : '' - } - ${ - stake_enabled - ? ` - , "CommunityStakes"."community_id" AS "CommunityStakes.community_id", - "CommunityStakes"."stake_id" AS "CommunityStakes.stake_id", - "CommunityStakes"."stake_token" AS "CommunityStakes.stake_token", - "CommunityStakes"."vote_weight" AS "CommunityStakes.vote_weight", - "CommunityStakes"."stake_enabled" AS "CommunityStakes.stake_enabled", - "CommunityStakes"."created_at" AS "CommunityStakes.created_at", - "CommunityStakes"."updated_at" AS "CommunityStakes.updated_at"` - : '' - } ${ include_node_info ? ` @@ -184,6 +174,12 @@ export function GetCommunities(): Query { : '' } ) AS "Community" + LEFT OUTER JOIN "CommunityTags" AS "CommunityTags" + ON "Community"."id" = "CommunityTags"."community_id" + LEFT OUTER JOIN "Tags" AS "CommunityTags->Tag" + ON "CommunityTags"."tag_id" = "CommunityTags->Tag"."id" + LEFT OUTER JOIN "CommunityStakes" AS "CommunityStakes" + ON "Community"."id" = "CommunityStakes"."community_id" ${ has_groups ? ` @@ -192,25 +188,6 @@ export function GetCommunities(): Query { ` : '' } - ${ - filtering_tags - ? ` - LEFT OUTER JOIN "CommunityTags" AS "CommunityTags" - ON "Community"."id" = "CommunityTags"."community_id" - LEFT OUTER JOIN "Tags" AS "CommunityTags->Tag" - ON "CommunityTags"."tag_id" = "CommunityTags->Tag"."id" - ` - : '' - } - ${ - stake_enabled - ? ` - INNER JOIN "CommunityStakes" AS "CommunityStakes" - ON "Community"."id" = "CommunityStakes"."community_id" - AND "CommunityStakes"."stake_enabled" = true - ` - : '' - } ${ include_node_info ? `