Skip to content

Commit

Permalink
fix: optimize query smart contract
Browse files Browse the repository at this point in the history
  • Loading branch information
fibonacci998 committed Aug 29, 2024
1 parent 0714077 commit a2a2998
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/services/evm/crawl_contract_evm.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,23 @@ export default class CrawlSmartContractEVMService extends BullableService {
return;
}

const [fromTx, toTx] = await Promise.all([
EVMTransaction.query()
.select('id')
.findOne('height', '>', startBlock)
.orderBy('height', 'asc')
.orderBy('index', 'asc')
.limit(1),
EVMTransaction.query()
.select('id')
.findOne('height', '<=', endBlock)
.orderBy('height', 'desc')
.orderBy('index', 'desc')
.limit(1),
]);
if (!fromTx || !toTx) {
return;
}
const evmTxs = await EVMTransaction.query()
.select(
'evm_transaction.height',
Expand All @@ -80,12 +97,14 @@ export default class CrawlSmartContractEVMService extends BullableService {
EvmInternalTransaction.TYPE.CREATE,
EvmInternalTransaction.TYPE.CREATE2,
])
.andWhere('id', '>=', fromTx.id)
.andWhere('id', '<=', toTx.id)
.andWhere('error', null);
})
.where('evm_transaction.height', '>', startBlock)
.andWhere('evm_transaction.height', '<=', endBlock)
.orderBy('evm_transaction.id', 'ASC')
.orderBy('evm_transaction.height', 'ASC');
.orderBy('evm_transaction.height', 'ASC')
.orderBy('evm_transaction.index', 'ASC');

let addresses: string[] = [];
const txCreationWithAdressses: Dictionary<EVMTransaction> = {};
Expand Down

0 comments on commit a2a2998

Please sign in to comment.