Skip to content

Commit

Permalink
fix: interactions for contracts group sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
ppedziwiatr committed Aug 10, 2022
1 parent e1c67b9 commit 23dbf16
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@ gateway_dump
yarn-error.log
.yalc
dump_*
tools/
24 changes: 10 additions & 14 deletions src/gateway/router/routes/interactionsContractGroupsRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 ?;
`;

Expand All @@ -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 = {
Expand All @@ -116,7 +112,7 @@ export async function interactionsContractGroupsRoute(ctx: Router.RouterContext)
page: parsedPage
},

interactions: grouped,
interactions,
};
} catch (e: any) {
ctx.logger.error(e);
Expand Down

0 comments on commit 23dbf16

Please sign in to comment.