Skip to content

Commit 331ad7b

Browse files
authored
Merge pull request #2720 from IntersectMBO/feat/add-pagination-to-drep-sql
fix: fetching latest voting anchor images
2 parents 86235b8 + 5e42a0a commit 331ad7b

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

govtool/backend/sql/list-dreps.sql

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,30 @@ FetchError AS (
6767
),
6868
LatestExistingVotingAnchor AS (
6969
SELECT
70-
dr.id AS drep_registration_id,
71-
dr.drep_hash_id,
72-
va.id AS voting_anchor_id,
73-
va.url,
74-
encode(va.data_hash, 'hex') AS metadata_hash
75-
FROM
76-
drep_registration dr
77-
JOIN voting_anchor va ON dr.voting_anchor_id = va.id
78-
JOIN off_chain_vote_data ocvd ON va.id = ocvd.voting_anchor_id
70+
subquery.drep_registration_id,
71+
subquery.drep_hash_id,
72+
subquery.voting_anchor_id,
73+
subquery.url,
74+
subquery.metadata_hash,
75+
subquery.ocvd_id
76+
FROM (
77+
SELECT
78+
dr.id AS drep_registration_id,
79+
dr.drep_hash_id,
80+
va.id AS voting_anchor_id,
81+
va.url,
82+
encode(va.data_hash, 'hex') AS metadata_hash,
83+
ocvd.id AS ocvd_id,
84+
ROW_NUMBER() OVER (PARTITION BY dr.drep_hash_id ORDER BY dr.tx_id DESC) AS rn
85+
FROM
86+
drep_registration dr
87+
JOIN voting_anchor va ON dr.voting_anchor_id = va.id
88+
JOIN off_chain_vote_data ocvd ON va.id = ocvd.voting_anchor_id
89+
WHERE
90+
ocvd.voting_anchor_id IS NOT NULL
91+
) subquery
7992
WHERE
80-
ocvd.voting_anchor_id IS NOT NULL
81-
ORDER BY
82-
dr.tx_id DESC
93+
subquery.rn = 1
8394
),
8495
HasNonDeregisterVotingAnchor AS (
8596
SELECT

0 commit comments

Comments
 (0)