Skip to content

Commit

Permalink
Ferrodri/agora 1687 citizens with most voting power are not sorted co…
Browse files Browse the repository at this point in the history
…rrectly (#151)

* add coalesce to sort by desc

* minor typo

* sort byaddress_metadata.address to be able to paginate
  • Loading branch information
ferrodri committed Mar 4, 2024
1 parent 0c556c5 commit 7cedfcf
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/app/api/common/citizens/getCitizens.ts
Expand Up @@ -34,8 +34,7 @@ export async function getCitizensForNamespace({
`
SELECT address_metadata.address, address_metadata.metadata, delegate.voting_power
FROM agora.address_metadata address_metadata
LEFT JOIN ${
namespace + ".delegates"
LEFT JOIN ${namespace + ".delegates"
} delegate ON LOWER(address_metadata.address) = LOWER(delegate.delegate)
WHERE address_metadata.kind = 'citizen'
AND address_metadata.dao_slug = 'OP'
Expand All @@ -52,12 +51,12 @@ export async function getCitizensForNamespace({
`
SELECT address_metadata.address, address_metadata.metadata, delegate.voting_power
FROM agora.address_metadata address_metadata
LEFT JOIN ${
namespace + ".delegates"
} delegate ON LOWER(address_metadata.address) = LOWER(delegate.delegate)
LEFT JOIN ${namespace + ".delegates"
} delegate ON LOWER(address_metadata.address) = LOWER(delegate.delegate)
WHERE address_metadata.kind = 'citizen'
AND address_metadata.dao_slug = 'OP'
ORDER BY delegate.voting_power DESC
ORDER BY COALESCE(delegate.voting_power, 0) DESC,
address_metadata.address ASC
OFFSET $1
LIMIT $2;
`,
Expand Down

0 comments on commit 7cedfcf

Please sign in to comment.