Skip to content

Commit

Permalink
fix: sql cte syntax and useless fields
Browse files Browse the repository at this point in the history
  • Loading branch information
brady.ouren committed Sep 9, 2024
1 parent 6469cd9 commit d13d425
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
2 changes: 0 additions & 2 deletions src/datastore/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ export interface DbTxWithAddressTransfers extends DbTx {
nft_transfer: number;
nft_mint: number;
nft_burn: number;
total_count: number;
}

export interface DbTxGlobalStatus {
Expand Down Expand Up @@ -1041,7 +1040,6 @@ export interface AddressTransfersTxQueryResult extends TxQueryResult {
nft_transfer: number;
nft_mint: number;
nft_burn: number;
total_count: number;
}

export interface DbAddressTransactionEvent {
Expand Down
1 change: 0 additions & 1 deletion src/datastore/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,6 @@ export function parseAccountTransferSummaryTxQueryResult(
nft_transfer: result.nft_transfer,
nft_mint: result.nft_mint,
nft_burn: result.nft_burn,
total_count: result.total_count,
};
}

Expand Down
8 changes: 4 additions & 4 deletions src/datastore/pg-store-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,8 @@ export class PgStoreV2 extends BasePgStoreModule {
FROM nft_events
WHERE sender = ${args.address} OR recipient = ${args.address}
)
)
total_count AS (
),
count AS (
SELECT COUNT(*)::int AS total_count
FROM address_txs
INNER JOIN txs USING (tx_id, index_block_hash, microblock_hash)
Expand Down Expand Up @@ -578,15 +578,15 @@ export class PgStoreV2 extends BasePgStoreModule {
SELECT COUNT(*)::int FROM nft_events
WHERE ${eventAcctCond} AND asset_event_type_id = ${DbAssetEventTypeId.Burn}
) AS nft_burn,
(SELECT total_count FROM total_count) AS total_count
(SELECT total_count FROM count) AS count
FROM address_txs
INNER JOIN txs USING (tx_id, index_block_hash, microblock_hash)
WHERE canonical = TRUE AND microblock_canonical = TRUE
ORDER BY block_height DESC, microblock_sequence DESC, tx_index DESC
LIMIT ${limit}
OFFSET ${offset}
`;
const total = resultQuery.length > 0 ? resultQuery[0].total_count : 0;
const total = resultQuery.length > 0 ? resultQuery[0].count : 0;
const parsed = resultQuery.map(r => parseAccountTransferSummaryTxQueryResult(r));
return {
total,
Expand Down
9 changes: 9 additions & 0 deletions src/tests/address-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,15 @@ describe('address tests', () => {
burn: 0,
});

// fetch with offset
const v2Fetch1offset = await supertest(api.server).get(
`/extended/v2/addresses/${testAddr2}/transactions?offset=1`
);
expect(v2Fetch1offset.status).toBe(200);
expect(v2Fetch1offset.type).toBe('application/json');
const v2Fetch1offsetJson = JSON.parse(v2Fetch1offset.text);
expect(v2Fetch1offsetJson.total).toBe(7);

const v2Fetch2 = await supertest(api.server).get(
`/extended/v2/addresses/${testAddr2}/transactions/${v2Fetch1Json.results[0].tx.tx_id}/events?limit=3`
);
Expand Down

0 comments on commit d13d425

Please sign in to comment.