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

Some cleanup on expensive query #796

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
15 changes: 11 additions & 4 deletions packages/helium-vote-service/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,14 @@ WITH
WHERE
registrar = ${escapedRegistrar}
),
vote_counts as (
SELECT
voter,
COUNT(DISTINCT proposal) AS numProposalsVoted,
MAX(created_at) AS lastVotedAt
FROM vote_markers
GROUP BY voter
),
proxies_with_assignments AS (
SELECT
name,
Expand Down Expand Up @@ -209,11 +217,10 @@ WITH
)
SELECT
pa.*,
COUNT(distinct vm.proposal) as "numProposalsVoted",
MAX(vm.created_at) as "lastVotedAt"
COALESCE(vc.numProposalsVoted, 0) AS "numProposalsVoted",
vc.lastVotedAt
FROM proxies_with_assignments pa
LEFT OUTER JOIN vote_markers vm ON vm.voter = pa.wallet
GROUP BY pa.name, pa.image, pa.wallet, pa.description, pa.detail, pa."numAssignments", pa."proxiedVeTokens", pa.percent
LEFT JOIN vote_counts vc ON vc.voter = pa.wallet
ORDER BY "proxiedVeTokens" DESC NULLS LAST
OFFSET ${offset}
LIMIT ${limit};
Expand Down
Loading