From c339facbf688df1fd905d1d554e6d00ec5235058 Mon Sep 17 00:00:00 2001 From: KoT_B_KocMoce <49576827+hodlonaut@users.noreply.github.com> Date: Sat, 9 Nov 2024 22:24:12 +1100 Subject: [PATCH] Update proposal_voting_summary.sql More efficient way of calculating last tx id in epoch --- files/grest/rpc/governance/proposal_voting_summary.sql | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/files/grest/rpc/governance/proposal_voting_summary.sql b/files/grest/rpc/governance/proposal_voting_summary.sql index b85111f9..ce665f8a 100644 --- a/files/grest/rpc/governance/proposal_voting_summary.sql +++ b/files/grest/rpc/governance/proposal_voting_summary.sql @@ -159,8 +159,9 @@ BEGIN INNER JOIN public.stake_address AS sa ON pu.reward_addr_id = sa.id INNER JOIN delegation_vote AS dv on dv.addr_id = sa.id AND dv.tx_id = (SELECT max(tx_id) FROM delegation_vote dv2 WHERE dv2.addr_id = sa.id - AND tx_id <= (SELECT COALESCE(max(t.id), (SELECT max(t2.id) FROM tx t2)) FROM tx t INNER JOIN block b ON t.block_id = b.id - AND b.epoch_no = ped.epoch_of_interest)) + AND tx_id <= + (SELECT COALESCE(t.id, (SELECT id FROM tx t2 ORDER BY id DESC LIMIT 1)) FROM tx t INNER JOIN block b + ON t.block_id = b.id AND b.epoch_no = ped.epoch_of_interest ORDER BY t.id DESC LIMIT 1)) INNER JOIN drep_hash AS dh on dh.id = dv.drep_hash_id and dh.view like 'drep_always%' INNER JOIN pool_stat AS pstat ON api.pool_hash_id = pstat.pool_hash_id