From d13d4258ab5461d5690b35e9dc01f56fb1a06216 Mon Sep 17 00:00:00 2001 From: "brady.ouren" Date: Mon, 9 Sep 2024 08:37:21 -0700 Subject: [PATCH] fix: sql cte syntax and useless fields --- src/datastore/common.ts | 2 -- src/datastore/helpers.ts | 1 - src/datastore/pg-store-v2.ts | 8 ++++---- src/tests/address-tests.ts | 9 +++++++++ 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/datastore/common.ts b/src/datastore/common.ts index 1c1b516ea..e0f3cdfdd 100644 --- a/src/datastore/common.ts +++ b/src/datastore/common.ts @@ -251,7 +251,6 @@ export interface DbTxWithAddressTransfers extends DbTx { nft_transfer: number; nft_mint: number; nft_burn: number; - total_count: number; } export interface DbTxGlobalStatus { @@ -1041,7 +1040,6 @@ export interface AddressTransfersTxQueryResult extends TxQueryResult { nft_transfer: number; nft_mint: number; nft_burn: number; - total_count: number; } export interface DbAddressTransactionEvent { diff --git a/src/datastore/helpers.ts b/src/datastore/helpers.ts index c0dab3219..0780a3b0b 100644 --- a/src/datastore/helpers.ts +++ b/src/datastore/helpers.ts @@ -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, }; } diff --git a/src/datastore/pg-store-v2.ts b/src/datastore/pg-store-v2.ts index 4c143cbde..1ed445bbd 100644 --- a/src/datastore/pg-store-v2.ts +++ b/src/datastore/pg-store-v2.ts @@ -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) @@ -578,7 +578,7 @@ 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 @@ -586,7 +586,7 @@ export class PgStoreV2 extends BasePgStoreModule { 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, diff --git a/src/tests/address-tests.ts b/src/tests/address-tests.ts index e22b37b28..1541d1b5d 100644 --- a/src/tests/address-tests.ts +++ b/src/tests/address-tests.ts @@ -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` );