Skip to content

Commit

Permalink
Always return stake and tag data.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnaviask committed Aug 7, 2024
1 parent a69aa60 commit 7935af2
Showing 1 changed file with 18 additions and 41 deletions.
59 changes: 18 additions & 41 deletions libs/model/src/community/GetCommunities.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,18 @@ export function GetCommunities(): Query<typeof schemas.GetCommunities> {
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
? `
Expand All @@ -50,27 +61,6 @@ export function GetCommunities(): Query<typeof schemas.GetCommunities> {
`
: ''
}
${
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
? `
Expand Down Expand Up @@ -184,6 +174,12 @@ export function GetCommunities(): Query<typeof schemas.GetCommunities> {
: ''
}
) 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
? `
Expand All @@ -192,25 +188,6 @@ export function GetCommunities(): Query<typeof schemas.GetCommunities> {
`
: ''
}
${
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
? `
Expand Down

0 comments on commit 7935af2

Please sign in to comment.