From 39af0b101ac491eefea7ec809a1a151a9b9cca39 Mon Sep 17 00:00:00 2001 From: Udhayakumari Date: Wed, 28 Jun 2023 07:08:29 +0000 Subject: [PATCH] Blocks pagination query fix in the backend Signed-off-by: Udhayakumari --- app/persistence/fabric/CRUDService.ts | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/app/persistence/fabric/CRUDService.ts b/app/persistence/fabric/CRUDService.ts index 30ddbf9aa..995f6474d 100644 --- a/app/persistence/fabric/CRUDService.ts +++ b/app/persistence/fabric/CRUDService.ts @@ -171,19 +171,14 @@ export class CRUDService { blocks.channel_genesis_hash =$1 AND blocks.network_name = $2 AND blocknum >= 0 AND blocks.createdt between $3 AND $4 ORDER BY blocks.blocknum desc) a WHERE a.txhash IS NOT NULL LIMIT $6 OFFSET (($5 - 1) * $6)`; } else { - sqlBlockTxList =`SELECT c.name AS channelname, - b.blocknum, b.txcount, b.datahash, b.blockhash, b.prehash,b.createdt, b.blksize, - array_agg(t.txhash) AS txhash - FROM channel c - INNER JOIN blocks b ON b.channel_genesis_hash = c.channel_genesis_hash AND - b.network_name = c.network_name - INNER JOIN transactions t ON t.blockid = b.blocknum AND t.channel_genesis_hash = c.channel_genesis_hash - AND t.network_name = c.network_name AND t.createdt between $3 and $4 = c.createdt between $3 and $4 - AND t.creator_msp_id IS NOT NULL AND t.creator_msp_id != ' ' AND length(t.creator_msp_id) > 0 - WHERE c.channel_genesis_hash =$1 AND c.network_name = $2 AND b.blocknum >= 0 ${byOrgs} AND b.createdt between $3 and $4 - GROUP BY c.name, b.blocknum, b.txcount, b.datahash, b.blockhash, b.prehash,b.createdt, b.blksize - ORDER BY b.blocknum DESC - LIMIT $6 OFFSET (($5 - 1) * $6)`; + sqlBlockTxList = `SELECT a.* FROM ( + SELECT (SELECT c.name FROM channel c WHERE c.channel_genesis_hash =$1 AND c.network_name = $2) + as channelname, blocks.blocknum,blocks.txcount ,blocks.datahash ,blocks.blockhash ,blocks.prehash,blocks.createdt, blocks.blksize, ( + SELECT array_agg(txhash) as txhash FROM transactions WHERE blockid = blocks.blocknum ${byOrgs} + AND transactions.creator_msp_id IS NOT NULL + AND channel_genesis_hash = $1 AND network_name = $2 AND createdt between $3 AND $4) FROM blocks WHERE + blocks.channel_genesis_hash =$1 AND blocks.network_name = $2 AND blocknum >= 0 AND blocks.createdt between $3 AND $4 + ORDER BY blocks.blocknum desc) a WHERE a.txhash IS NOT NULL LIMIT $6 OFFSET (($5 - 1) * $6)`; } if (page == 1) { let sqlBlockTxCount: string;