Skip to content

Commit 0473534

Browse files
authored
Filter pending blocks as well as canonical (#115)
1 parent eecdea0 commit 0473534

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/db/sql/events-actions/queries.ts

+10
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ function fullChainCTE(db_client: postgres.Sql, from?: string, to?: string) {
3131
AND pending_chain.id <> pending_chain.parent_id
3232
AND pending_chain.chain_status <> 'canonical'
3333
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+
}
3444
),
3545
full_chain AS (
3646
SELECT

0 commit comments

Comments
 (0)