Skip to content

Commit

Permalink
add support to lower slot limit as -1 to get the full range
Browse files Browse the repository at this point in the history
  • Loading branch information
ecioppettini committed Mar 4, 2024
1 parent b0702f8 commit e1bca8e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ export interface ISlotBoundsPaginationParams {

/** 'SlotBoundsPagination' return type */
export interface ISlotBoundsPaginationResult {
max_slot: number;
max_tx_id: string | null;
min_slot: number;
min_tx_id: string | null;
}

Expand All @@ -21,7 +19,7 @@ export interface ISlotBoundsPaginationQuery {
result: ISlotBoundsPaginationResult;
}

const slotBoundsPaginationIR: any = {"usedParamSet":{"low":true,"high":true},"params":[{"name":"low","required":true,"transform":{"type":"scalar"},"locs":[{"a":155,"b":159}]},{"name":"high","required":true,"transform":{"type":"scalar"},"locs":[{"a":409,"b":414}]}],"statement":"WITH\n low_block AS (\n SELECT\n \"Block\".id,\n \"Block\".slot\n FROM\n \"Block\"\n WHERE\n slot <= :low! AND tx_count > 0\n ORDER BY\n \"Block\".id DESC\n LIMIT\n 1\n ),\n high_block AS (\n SELECT\n \"Block\".id,\n \"Block\".slot\n FROM\n \"Block\"\n WHERE\n slot <= :high! AND tx_count > 0\n ORDER BY\n \"Block\".id DESC\n LIMIT\n 1\n ),\n min_hash AS (\n SELECT\n COALESCE(MAX(\"Transaction\".id), -1) AS min_tx_id,\n slot AS min_slot\n FROM\n \"Transaction\"\n JOIN low_block ON \"Transaction\".block_id = low_block.id\n GROUP BY\n low_block.slot\n LIMIT\n 1\n ),\n max_hash AS (\n SELECT\n COALESCE(MAX(\"Transaction\".id), -2) AS max_tx_id,\n slot AS max_slot\n FROM\n \"Transaction\"\n JOIN high_block ON \"Transaction\".block_id = high_block.id\n GROUP BY\n high_block.slot\n )\nSELECT\n *\nFROM min_hash\nLEFT JOIN max_hash ON 1 = 1"};
const slotBoundsPaginationIR: any = {"usedParamSet":{"low":true,"high":true},"params":[{"name":"low","required":true,"transform":{"type":"scalar"},"locs":[{"a":155,"b":159}]},{"name":"high","required":true,"transform":{"type":"scalar"},"locs":[{"a":409,"b":414}]}],"statement":"WITH\n low_block AS (\n SELECT\n \"Block\".id,\n \"Block\".slot\n FROM\n \"Block\"\n WHERE\n slot <= :low! AND tx_count > 0\n ORDER BY\n \"Block\".id DESC\n LIMIT\n 1\n ),\n high_block AS (\n SELECT\n \"Block\".id,\n \"Block\".slot\n FROM\n \"Block\"\n WHERE\n slot <= :high! AND tx_count > 0\n ORDER BY\n \"Block\".id DESC\n LIMIT 1\n ),\n min_hash AS (\n (SELECT\n COALESCE(MAX(\"Transaction\".id), -1) AS min_tx_id\n FROM\n \"Transaction\"\n JOIN low_block ON \"Transaction\".block_id = low_block.id\n GROUP BY\n low_block.slot\n LIMIT\n 1\n )\n UNION (SELECT min_tx_id FROM (values(-1)) s(min_tx_id))\n ORDER BY min_tx_id DESC\n LIMIT\n 1\n ),\n max_hash AS (\n SELECT\n COALESCE(MAX(\"Transaction\".id), -2) AS max_tx_id\n FROM\n \"Transaction\"\n JOIN high_block ON \"Transaction\".block_id = high_block.id\n GROUP BY\n high_block.slot\n )\nSELECT\n *\nFROM min_hash\nLEFT JOIN max_hash ON 1 = 1"};

/**
* Query generated from SQL:
Expand Down Expand Up @@ -50,25 +48,27 @@ const slotBoundsPaginationIR: any = {"usedParamSet":{"low":true,"high":true},"pa
* slot <= :high! AND tx_count > 0
* ORDER BY
* "Block".id DESC
* LIMIT
* 1
* LIMIT 1
* ),
* min_hash AS (
* SELECT
* COALESCE(MAX("Transaction".id), -1) AS min_tx_id,
* slot AS min_slot
* (SELECT
* COALESCE(MAX("Transaction".id), -1) AS min_tx_id
* FROM
* "Transaction"
* JOIN low_block ON "Transaction".block_id = low_block.id
* GROUP BY
* low_block.slot
* LIMIT
* 1
* )
* UNION (SELECT min_tx_id FROM (values(-1)) s(min_tx_id))
* ORDER BY min_tx_id DESC
* LIMIT
* 1
* ),
* max_hash AS (
* SELECT
* COALESCE(MAX("Transaction".id), -2) AS max_tx_id,
* slot AS max_slot
* COALESCE(MAX("Transaction".id), -2) AS max_tx_id
* FROM
* "Transaction"
* JOIN high_block ON "Transaction".block_id = high_block.id
Expand Down
16 changes: 9 additions & 7 deletions webserver/server/app/models/pagination/slotBoundsPagination.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,27 @@ WITH
slot <= :high! AND tx_count > 0
ORDER BY
"Block".id DESC
LIMIT
1
LIMIT 1
),
min_hash AS (
SELECT
COALESCE(MAX("Transaction".id), -1) AS min_tx_id,
slot AS min_slot
(SELECT
COALESCE(MAX("Transaction".id), -1) AS min_tx_id
FROM
"Transaction"
JOIN low_block ON "Transaction".block_id = low_block.id
GROUP BY
low_block.slot
LIMIT
1
)
UNION (SELECT min_tx_id FROM (values(-1)) s(min_tx_id))
ORDER BY min_tx_id DESC
LIMIT
1
),
max_hash AS (
SELECT
COALESCE(MAX("Transaction".id), -2) AS max_tx_id,
slot AS max_slot
COALESCE(MAX("Transaction".id), -2) AS max_tx_id
FROM
"Transaction"
JOIN high_block ON "Transaction".block_id = high_block.id
Expand Down

0 comments on commit e1bca8e

Please sign in to comment.