@@ -30,17 +30,6 @@ function fullChainCTE(db_client: postgres.Sql, from?: string, to?: string) {
30
30
INNER JOIN pending_chain ON b.id = pending_chain.parent_id
31
31
AND pending_chain.id <> pending_chain.parent_id
32
32
AND pending_chain.chain_status <> 'canonical'
33
- WHERE 1=1
34
- ${
35
- // If fromAsNum is not undefined, then we have also set toAsNum and can safely query the range
36
- // If no params ar provided, then we query the last BLOCK_RANGE_SIZE blocks
37
- fromAsNum
38
- ? db_client `AND b.height >= ${ fromAsNum } AND b.height < ${ toAsNum ! } `
39
- : db_client `AND b.height >= (
40
- SELECT MAX(b2.height)
41
- FROM blocks b2
42
- ) - ${ BLOCK_RANGE_SIZE } `
43
- }
44
33
),
45
34
full_chain AS (
46
35
SELECT
@@ -51,6 +40,17 @@ function fullChainCTE(db_client: postgres.Sql, from?: string, to?: string) {
51
40
id, state_hash, parent_id, parent_hash, height, global_slot_since_genesis, global_slot_since_hard_fork, timestamp, chain_status, ledger_hash, last_vrf_output
52
41
FROM
53
42
pending_chain
43
+ WHERE 1=1
44
+ ${
45
+ // If fromAsNum is not undefined, then we have also set toAsNum and can safely query the range
46
+ // If no params ar provided, then we query the last BLOCK_RANGE_SIZE blocks
47
+ fromAsNum
48
+ ? db_client `AND height >= ${ fromAsNum } AND height < ${ toAsNum ! } `
49
+ : db_client `AND height >= (
50
+ SELECT MAX(height)
51
+ FROM pending_chain
52
+ ) - ${ BLOCK_RANGE_SIZE } `
53
+ }
54
54
UNION ALL
55
55
SELECT
56
56
id, state_hash, parent_id, parent_hash, height, global_slot_since_genesis, global_slot_since_hard_fork, timestamp, chain_status, ledger_hash, last_vrf_output
0 commit comments