Skip to content

Commit

Permalink
Calculate minimum transaction id in scope of after-block-height restr…
Browse files Browse the repository at this point in the history
…iction in a slightly more efficient way
  • Loading branch information
Greg B authored and rdlrt committed Nov 29, 2024
1 parent 5985b92 commit e65c90c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
18 changes: 14 additions & 4 deletions files/grest/rpc/account/account_txs.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,20 @@ DECLARE
_tx_id_list bigint[];
_stake_address_id integer;
BEGIN
SELECT INTO _tx_id_min id
FROM tx
WHERE block_id >= (SELECT id FROM block WHERE block_no >= _after_block_height ORDER BY id limit 1)
ORDER BY id limit 1;

SELECT INTO _tx_id_min min(id)
FROM tx
WHERE block_id = (
SELECT id
FROM block AS b
WHERE block_no >= _after_block_height
AND EXISTS (
SELECT true
FROM tx t
WHERE t.block_id = b.id
)
ORDER BY id LIMIT 1
);

SELECT INTO _stake_address_id id FROM stake_address WHERE hash_raw = (SELECT DECODE(b32_decode(_stake_address), 'hex'));

Expand Down
17 changes: 13 additions & 4 deletions files/grest/rpc/address/address_txs.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,19 @@ DECLARE
_tx_id_min bigint;
_tx_id_list bigint[];
BEGIN
SELECT INTO _tx_id_min id
FROM tx
WHERE block_id >= (SELECT id FROM block WHERE block_no >= _after_block_height ORDER BY id limit 1)
ORDER BY id limit 1;
SELECT INTO _tx_id_min min(id)
FROM tx
WHERE block_id = (
SELECT id
FROM block AS b
WHERE block_no >= _after_block_height
AND EXISTS (
SELECT true
FROM tx t
WHERE t.block_id = b.id
)
ORDER BY id LIMIT 1
);

-- all tx_out & tx_in tx ids
SELECT INTO _tx_id_list ARRAY_AGG(tx_id)
Expand Down

0 comments on commit e65c90c

Please sign in to comment.