Skip to content

Commit

Permalink
fix: remove accidental cartesian product of blocks_pushes * `blocks…
Browse files Browse the repository at this point in the history
…` in pending proposal date query (#62)
  • Loading branch information
zone117x authored Nov 25, 2024
1 parent 8b3b844 commit 1bcc4c1
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/pg/pg-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1066,18 +1066,17 @@ export class PgStore extends BasePgStore {
received_at: Date | null;
}[]
>`
WITH last_confirmed_height AS (
SELECT GREATEST(
COALESCE(MAX(b.block_height), 0),
COALESCE(MAX(bp.block_height), 0)
) AS height
FROM blocks b
LEFT JOIN block_pushes bp ON true
WITH max_heights AS (
SELECT
GREATEST(
(SELECT COALESCE(MAX(block_height), 0) FROM blocks),
(SELECT COALESCE(MAX(block_height), 0) FROM block_pushes)
) AS height
),
oldest_pending_proposal AS (
SELECT received_at
FROM block_proposals bp
WHERE bp.block_height > (SELECT height FROM last_confirmed_height)
WHERE bp.block_height > (SELECT height FROM max_heights)
ORDER BY received_at ASC
LIMIT 1
)
Expand Down

0 comments on commit 1bcc4c1

Please sign in to comment.