Skip to content

Commit

Permalink
fix: schema and sql query
Browse files Browse the repository at this point in the history
  • Loading branch information
boray committed Jan 10, 2025
1 parent 630b3d5 commit 9e4e7ce
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,5 @@ type ActionOutput {
type Query {
events(input: EventFilterOptionsInput!): [EventOutput]!
actions(input: ActionFilterOptionsInput!): [ActionOutput]!
maxBlockHeightInfo: MaxBlockHeightInfo!
block: MaxBlockHeightInfo!
}
24 changes: 12 additions & 12 deletions src/db/sql/events-actions/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,19 +373,19 @@ export function getActionsQuery(

export function getBlockQuery(db_client: postgres.Sql) {
return db_client`
WITH max_height AS (
SELECT MAX(height) AS max_height
WITH max_heights AS (
SELECT
chain_status,
MAX(height) AS max_height
FROM blocks
)
SELECT *
FROM blocks
WHERE height = (SELECT max_height FROM max_height)
AND chain_status = 'canonical'
UNION
SELECT *
FROM blocks
WHERE height = (SELECT max_height FROM max_height)
AND chain_status = 'pending'
WHERE chain_status IN ('canonical', 'pending')
GROUP BY chain_status
)
SELECT b.*
FROM blocks b
JOIN max_heights mh
ON b.chain_status = mh.chain_status
AND b.height = mh.max_height;
`;
}

Expand Down
4 changes: 2 additions & 2 deletions src/services/blocks-service/block-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ class BlockService implements IBlockService {
const processingSpan = tracingState.startSpan('block.processing');
const blockData = {
canonicalMaxBlockHeight: Number(
rows.filter((row) => row.chain_status === 'canonical')[0]
rows.filter((row) => row.chain_status === 'canonical')[0].height
),
pendingMaxBlockHeight: Number(
rows.filter((row) => row.chain_status === 'pending')[0]
rows.filter((row) => row.chain_status === 'pending')[0].height
),
};
processingSpan.end();
Expand Down

0 comments on commit 9e4e7ce

Please sign in to comment.