Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LW-11640 Fix queries performances issue #1501

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,9 @@ export class ChainHistoryBuilder {
values: [ids]
});
const redeemerMap: TransactionDataMap<Cardano.Redeemer[]> = new Map();
for (const redeemer of result.rows) {
for (const redeemer of result.rows
.map(({ id, ...rest }) => ({ id: BigInt(id), ...rest }))
.sort((a, b) => Number(a.id - b.id))) {
const txId = redeemer.tx_id.toString('hex') as unknown as Cardano.TransactionId;
const currentRedeemers = redeemerMap.get(txId) ?? [];
redeemerMap.set(txId, [...currentRedeemers, mapRedeemer(redeemer)]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ const mapRedeemerPurpose = (purpose: RedeemerModel['purpose']): Cardano.Redeemer
throw new NotImplementedError(`Failed to map redeemer "purpose": ${purpose}`);
})();

export const mapRedeemer = (redeemerModel: RedeemerModel): Cardano.Redeemer => ({
export const mapRedeemer = (redeemerModel: Omit<RedeemerModel, 'id'>): Cardano.Redeemer => ({
data: stubRedeemerData,
executionUnits: {
memory: Number(redeemerModel.unit_mem),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,31 +37,14 @@ export const findTxCollateralsByIds = `
WHERE tx.id = ANY($1)
ORDER BY tx_in.id ASC`;

export const findTxInputsByAddresses = `
${selectTxInput()}
JOIN block ON tx.block_id = block.id
WHERE tx_out.address = ANY($1)
AND block.block_no >= $2
AND block.block_no <= $3
ORDER BY tx_in.id ASC`;

export const findTxOutputsByIds = `
${selectTxOutput()}
WHERE tx.id = ANY($1)
ORDER BY tx_out.id ASC`;

export const findTxOutputsByAddresses = `
${selectTxOutput()}
JOIN block ON tx.block_id = block.id
WHERE tx_out.address = ANY($1)
AND block.block_no >= $2
AND block.block_no <= $3
ORDER BY tx_out.id ASC`;

export const findCollateralOutputsByTxIds = `
${selectTxOutput(true)}
WHERE tx.id = ANY($1)
ORDER BY tx_out.id ASC`;
WHERE tx.id = ANY($1)`;

export const findTip = `
SELECT
Expand Down Expand Up @@ -176,6 +159,7 @@ export const findWithdrawalsByTxIds = `

export const findRedeemersByTxIds = `
SELECT
redeemer.id AS id,
redeemer."index" AS "index",
redeemer.purpose AS purpose,
redeemer.script_hash AS script_hash,
Expand All @@ -184,8 +168,7 @@ export const findRedeemersByTxIds = `
tx.hash AS tx_id
FROM redeemer
JOIN tx ON tx.id = redeemer.tx_id
WHERE tx.id = ANY($1)
ORDER BY redeemer.id ASC`;
WHERE tx.id = ANY($1)`;

export const findVotingProceduresByTxIds = `
SELECT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export interface WithdrawalModel {
}

export interface RedeemerModel {
id: string;
index: number;
purpose: 'cert' | 'mint' | 'spend' | 'reward' | 'voting' | 'proposing';
script_hash: Buffer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ describe('chain history mappers', () => {
);
});
describe('mapRedeemer', () => {
const redeemerModel: Omit<RedeemerModel, 'purpose'> = {
const redeemerModel: Omit<RedeemerModel, 'id' | 'purpose'> = {
index: 1,
script_hash: Buffer.from(hash28ByteBase16, 'hex'),
tx_id: Buffer.from(transactionHash, 'hex'),
Expand Down
Loading