Skip to content

Commit

Permalink
add index by address to cde_cardano_asset_utxos
Browse files Browse the repository at this point in the history
  • Loading branch information
ecioppettini committed Jan 4, 2024
1 parent cc5657f commit 7a0380e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
8 changes: 8 additions & 0 deletions packages/node-sdk/paima-db/src/paima-tables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,10 @@ CREATE TABLE cde_cardano_asset_utxos (
);
`;

const QUERY_CREATE_INDEX_CDE_CARDANO_ASSET_UTXOS_ADDRESS = `
CREATE INDEX CDE_CARDANO_ASSET_UTXOS_ADDRESS_INDEX ON "cde_cardano_asset_utxos" (ADDRESS);
`;

const TABLE_DATA_CDE_CARDANO_ASSET_UTXOS: TableData = {
tableName: 'cde_cardano_asset_utxos',
primaryKeyColumns: ['cde_id', 'tx_id', 'output_index'],
Expand All @@ -367,6 +371,10 @@ const TABLE_DATA_CDE_CARDANO_ASSET_UTXOS: TableData = {
]),
serialColumns: [],
creationQuery: QUERY_CREATE_TABLE_CDE_CARDANO_ASSET_UTXOS,
index: {
name: 'CDE_CARDANO_ASSET_UTXOS_ADDRESS_INDEX',
creationQuery: QUERY_CREATE_INDEX_CDE_CARDANO_ASSET_UTXOS_ADDRESS,
},
};

const QUERY_CREATE_TABLE_EMULATED = `
Expand Down
16 changes: 16 additions & 0 deletions packages/node-sdk/paima-db/src/postgres-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,22 @@ export async function createTable(pool: PoolClient, table: TableData): Promise<b
return false;
}

if (table.index) {
try {
await pool.query(`DROP INDEX IF EXISTS ${table.index.name}`);
} catch (err) {
doLog(`[database-validation] Error while dropping index: ${err}`);
return false;
}

try {
await pool.query(table.index.creationQuery);
} catch (err) {
doLog(`[database-validation] Error while creating index: ${err}`);
return false;
}
}

return true;
}

Expand Down
1 change: 1 addition & 0 deletions packages/node-sdk/paima-db/src/table-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface TableData {
columnData: ColumnData[];
serialColumns: string[];
creationQuery: string;
index?: { name: string; creationQuery: string };
}

function packTuple(tuple: ColumnDataTuple): ColumnData {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import type {
TokenIdPair,
CardanoAssetUtxo,
} from './types.js';
import { ICdeCardanoAssetUtxosByAddressParams } from '@paima/db/src/sql/cde-cardano-asset-utxos.queries.js';
import type { ICdeCardanoAssetUtxosByAddressParams } from '@paima/db/src/sql/cde-cardano-asset-utxos.queries.js';

/* Functions to retrieve CDE ID: */

Expand Down

0 comments on commit 7a0380e

Please sign in to comment.