Codegen changes for avoiding eth_getLogs when no subgraph event handlers exist

This commit is contained in:
Nabarun 2024-06-19 18:23:31 +05:30
parent 4d2816e61f
commit f63d35b336
2 changed files with 23 additions and 3 deletions

View File

@ -10,8 +10,7 @@
checkpointInterval = 2000 checkpointInterval = 2000
# Enable state creation # Enable state creation
# CAUTION: Disable only if state creation is not desired or can be filled subsequently enableState = false
enableState = true
{{#if (subgraphPath)}} {{#if (subgraphPath)}}
subgraphPath = "./subgraph-build" subgraphPath = "./subgraph-build"

View File

@ -829,6 +829,7 @@ export class Indexer implements IndexerInterface {
{{/each}} {{/each}}
} }
// eslint-disable-next-line @typescript-eslint/no-empty-function
_populateRelationsMap (): void { _populateRelationsMap (): void {
{{#each subgraphEntities as | subgraphEntity |}} {{#each subgraphEntities as | subgraphEntity |}}
{{#if subgraphEntity.relations}} {{#if subgraphEntity.relations}}
@ -867,7 +868,27 @@ export class Indexer implements IndexerInterface {
assert(blockHash); assert(blockHash);
assert(blockNumber); assert(blockNumber);
const { events: dbEvents, transactions } = await this._baseIndexer.fetchEvents(blockHash, blockNumber, this.eventSignaturesMap, this.parseEventNameAndArgs.bind(this)); {{#if (subgraphPath)}}
let dbEvents: DeepPartial<Event>[] = [];
let transactions: EthFullTransaction[] = [];
// Fetch events and txs only if subgraph config has any event handlers
if (this._graphWatcher.eventHandlerExists) {
({ events: dbEvents, transactions } = await this._baseIndexer.fetchEvents(
blockHash,
blockNumber,
this.eventSignaturesMap,
this.parseEventNameAndArgs.bind(this)
));
}
{{else~}}
const { events: dbEvents, transactions } = await this._baseIndexer.fetchEvents(
blockHash,
blockNumber,
this.eventSignaturesMap,
this.parseEventNameAndArgs.bind(this)
);
{{/if}}
const dbTx = await this._db.createTransactionRunner(); const dbTx = await this._db.createTransactionRunner();
try { try {