From 1971f50caf1ba9d6bb6ffde4340ad27f6c8598ff Mon Sep 17 00:00:00 2001 From: Torresmorah Date: Thu, 9 Nov 2023 13:16:40 -0600 Subject: [PATCH] fix(hapi-evm): limit get result --- hapi-evm/src/models/block/queries.ts | 12 ++++++++---- hapi-evm/src/models/transaction/queries.ts | 16 +++++++++++----- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/hapi-evm/src/models/block/queries.ts b/hapi-evm/src/models/block/queries.ts index 5fbfcbfba..cca53e91d 100644 --- a/hapi-evm/src/models/block/queries.ts +++ b/hapi-evm/src/models/block/queries.ts @@ -38,6 +38,7 @@ const internal_get = async ( // such as limit, order, etc where: object, order: object | null, + limit: number | null, attributes: string, operation?: string ): Promise => { @@ -45,7 +46,7 @@ const internal_get = async ( ${type} (${parameters}) { ${table}${ operation ? `_${operation}` : '' - }(where: $where, order_by: $order) { + }(where: $where, order_by: $order, limit: $limit) { ${attributes} } } @@ -53,7 +54,8 @@ const internal_get = async ( return await coreUtil.hasura.default.request(query, { where, - order + order, + limit }) } @@ -61,13 +63,14 @@ export const exist = async (hashOrNumber: string | number) => { const result = await internal_get( 'query', 'evm_block', - '$where: evm_block_bool_exp!, $order: [evm_block_order_by!]', + '$where: evm_block_bool_exp!, $order: [evm_block_order_by!], $limit: Int', { [typeof hashOrNumber === 'string' ? 'hash' : 'number']: { _eq: hashOrNumber } }, null, + null, 'aggregate { count }', 'aggregate' ) @@ -83,9 +86,10 @@ const get = async ( const result = await internal_get( 'query', 'evm_block', - '$where: evm_block_bool_exp!, $order: [evm_block_order_by!]', + '$where: evm_block_bool_exp!, $order: [evm_block_order_by!], $limit: Int', where, order, + !many ? 1 : null, 'hash, gas_used, transactions, number, timestamp' ) diff --git a/hapi-evm/src/models/transaction/queries.ts b/hapi-evm/src/models/transaction/queries.ts index a5ba86866..560541960 100644 --- a/hapi-evm/src/models/transaction/queries.ts +++ b/hapi-evm/src/models/transaction/queries.ts @@ -30,19 +30,23 @@ const internal_get = async ( // TODO: not only accept where but also additional content // such as limit, order, etc where: object, + limit: number | null, attributes: string, operation?: string ): Promise => { const gqlObj = gql` ${type} (${parameters}) { - ${table}${operation ? `_${operation}` : ''}(where: $where) { + ${table}${ + operation ? `_${operation}` : '' + }(where: $where, limit: $limit) { ${attributes} } } ` return await coreUtil.hasura.default.request(gqlObj, { - where + where, + limit }) } @@ -50,8 +54,9 @@ export const exist = async (hash: string) => { const result = await internal_get( Operation.query, 'evm_transaction', - '$where: evm_transaction_bool_exp!', + '$where: evm_transaction_bool_exp!, $limit: Int', { hash: { _eq: hash } }, + null, 'aggregate { count }', 'aggregate' ) @@ -63,9 +68,10 @@ const get = async (where: object, many = false) => { const result = await internal_get( 'query', 'evm_transaction', - '$where: evm_transaction_bool_exp!', + '$where: evm_transaction_bool_exp!, $limit: Int', where, - 'hash, gas_used, transactions, number, timestamp' + !many ? 1 : null, + 'hash, block_hash, block_number, gas, gas_price' ) return many ? result.evm_transaction : result.evm_transaction[0]