From e1bca8e74371561510373a8ffc72298625344aba Mon Sep 17 00:00:00 2001 From: Enzo Cioppettini Date: Fri, 1 Mar 2024 22:00:05 -0300 Subject: [PATCH] add support to lower slot limit as -1 to get the full range --- .../slotBoundsPagination.queries.ts | 20 +++++++++---------- .../pagination/slotBoundsPagination.sql | 16 ++++++++------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/webserver/server/app/models/pagination/slotBoundsPagination.queries.ts b/webserver/server/app/models/pagination/slotBoundsPagination.queries.ts index 0d903eaa..c3de9024 100644 --- a/webserver/server/app/models/pagination/slotBoundsPagination.queries.ts +++ b/webserver/server/app/models/pagination/slotBoundsPagination.queries.ts @@ -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; } @@ -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: @@ -50,13 +48,11 @@ 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 @@ -64,11 +60,15 @@ const slotBoundsPaginationIR: any = {"usedParamSet":{"low":true,"high":true},"pa * 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 diff --git a/webserver/server/app/models/pagination/slotBoundsPagination.sql b/webserver/server/app/models/pagination/slotBoundsPagination.sql index a8c3a69b..6fbaa75e 100644 --- a/webserver/server/app/models/pagination/slotBoundsPagination.sql +++ b/webserver/server/app/models/pagination/slotBoundsPagination.sql @@ -23,13 +23,11 @@ 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 @@ -37,11 +35,15 @@ WITH 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