From 23dbf160f87160123e9793532f6bd02cc46bba4b Mon Sep 17 00:00:00 2001 From: ppe Date: Wed, 10 Aug 2022 19:55:07 +0200 Subject: [PATCH] fix: interactions for contracts group sorting --- .gitignore | 1 - .../routes/interactionsContractGroupsRoute.ts | 24 ++++++++----------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index 1e0523b8..a394ed38 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,3 @@ gateway_dump yarn-error.log .yalc dump_* -tools/ diff --git a/src/gateway/router/routes/interactionsContractGroupsRoute.ts b/src/gateway/router/routes/interactionsContractGroupsRoute.ts index 09085f7c..03b89053 100644 --- a/src/gateway/router/routes/interactionsContractGroupsRoute.ts +++ b/src/gateway/router/routes/interactionsContractGroupsRoute.ts @@ -23,7 +23,7 @@ function loadInteractionsForSrcTx( WHERE c.src_tx_id = ? AND i.confirmation_status IN ('confirmed', 'not_processed') ${fromSortKey ? ' AND sort_key > ?' : ''} - ORDER BY i.contract_id ASC, i.sort_key ASC + ORDER i.sort_key ASC LIMIT ? OFFSET ?`; return gatewayDb.raw(query, bindings); @@ -68,7 +68,7 @@ function loadInteractionsForGroup( AND (s.src NOT LIKE '%readContractState%' AND s.src NOT LIKE '%unsafeClient%')) OR s.src_content_type = 'application/wasm') ${fromSortKey ? ' AND sort_key > ?' : ''} - ORDER BY i.contract_id ASC, i.sort_key ASC + ORDER BY i.sort_key ASC LIMIT ? OFFSET ?; `; @@ -95,18 +95,14 @@ export async function interactionsContractGroupsRoute(ctx: Router.RouterContext) logger.info(`Loading contract groups interactions: ${benchmark.elapsed()}`); - const grouped: any = {}; + const interactions = []; for (let row of result?.rows) { - if (!grouped[row.contractId]) { - grouped[row.contractId] = []; - } - grouped[row.contractId].push( - { - ...row.interaction, - confirmationStatus: row.confirmation_status, - sortKey: row.sort_key, - } - ) + interactions.push({ + contractId: row.contractId, + ...row.interaction, + confirmationStatus: row.confirmation_status, + sortKey: row.sort_key, + }); } ctx.body = { @@ -116,7 +112,7 @@ export async function interactionsContractGroupsRoute(ctx: Router.RouterContext) page: parsedPage }, - interactions: grouped, + interactions, }; } catch (e: any) { ctx.logger.error(e);