Accommodate GQL optimizations in codegen (#254)

* Prune optional methods in indexer and database interfaces

* Implement GQL optimization changes in codegen

* Fix graph-node test indexer

* Add demos to codegen package
This commit is contained in:
2022-11-23 17:42:25 +05:30
committed by GitHub
parent 0b33cc98c9
commit cc28474537
26 changed files with 758 additions and 57 deletions
-16
View File
@@ -482,22 +482,6 @@ export class Database {
async getLatestPrunedEntity<Entity> (repo: Repository<Entity>, id: string, canonicalBlockNumber: number): Promise<Entity | undefined> {
// Filter out latest entity from pruned blocks.
const entityInPrunedRegion = await repo.createQueryBuilder('entity')
.innerJoinAndSelect('block_progress', 'block', 'block.block_hash = entity.block_hash')
.where('block.is_pruned = false')
.andWhere('entity.id = :id', { id })
.andWhere('entity.block_number <= :canonicalBlockNumber', { canonicalBlockNumber })
.orderBy('entity.block_number', 'DESC')
.limit(1)
.getOne();
return entityInPrunedRegion;
}
async getLatestPrunedEntityWithoutJoin<Entity> (repo: Repository<Entity>, id: string, canonicalBlockNumber: number): Promise<Entity | undefined> {
// Filter out latest entity from pruned blocks.
const entityInPrunedRegion = await repo.createQueryBuilder('entity')
.where('entity.id = :id', { id })
.andWhere('entity.is_pruned = false')
-2
View File
@@ -687,7 +687,6 @@ export class Indexer {
}
// Call initial state hook.
assert(indexer.processInitialState);
const stateData = await indexer.processInitialState(contract.address, blockHash);
const block = await this.getBlockProgress(blockHash);
@@ -800,7 +799,6 @@ export class Indexer {
assert(currentBlock.blockNumber <= stateSyncStatus.latestIndexedBlockNumber, 'State should be indexed for checkpoint at a block');
// Call state checkpoint hook and check if default checkpoint is disabled.
assert(indexer.processStateCheckpoint);
const disableDefaultCheckpoint = await indexer.processStateCheckpoint(contractAddress, currentBlock.blockHash);
if (disableDefaultCheckpoint) {
-3
View File
@@ -423,10 +423,7 @@ export class JobRunner {
_updateWatchedContracts (job: any): void {
const { data: { contract } } = job;
assert(this._indexer.cacheContract);
this._indexer.cacheContract(contract);
this._indexer.updateStateStatusMap(contract.address, {});
}
}
+4 -5
View File
@@ -109,13 +109,12 @@ export interface IndexerInterface {
parseEventNameAndArgs?: (kind: string, logObj: any) => any
isWatchedContract: (address: string) => ContractInterface | undefined;
getContractsByKind?: (kind: string) => ContractInterface[]
cacheContract?: (contract: ContractInterface) => void;
cacheContract: (contract: ContractInterface) => void;
watchContract: (address: string, kind: string, checkpoint: boolean, startingBlock: number) => Promise<void>
getEntityTypesMap?: () => Map<string, { [key: string]: string }>
getRelationsMap?: () => Map<any, { [key: string]: any }>
createDiffStaged?: (contractAddress: string, blockHash: string, data: any) => Promise<void>
processInitialState?: (contractAddress: string, blockHash: string) => Promise<any>
processStateCheckpoint?: (contractAddress: string, blockHash: string) => Promise<boolean>
processInitialState: (contractAddress: string, blockHash: string) => Promise<any>
processStateCheckpoint: (contractAddress: string, blockHash: string) => Promise<boolean>
processBlock: (blockProgres: BlockProgressInterface) => Promise<void>
processBlockAfterEvents?: (blockHash: string, blockNumber: number) => Promise<void>
processCanonicalBlock (blockHash: string, blockNumber: number): Promise<void>
@@ -175,7 +174,7 @@ export interface DatabaseInterface {
getDiffStatesInRange (contractAddress: string, startBlock: number, endBlock: number): Promise<StateInterface[]>
getNewState (): StateInterface
removeStates(queryRunner: QueryRunner, blockNumber: number, kind: StateKind): Promise<void>
removeStatesAfterBlock?: (queryRunner: QueryRunner, blockNumber: number) => Promise<void>
removeStatesAfterBlock: (queryRunner: QueryRunner, blockNumber: number) => Promise<void>
saveOrUpdateState (queryRunner: QueryRunner, state: StateInterface): Promise<StateInterface>
getStateSyncStatus (): Promise<StateSyncStatusInterface | undefined>
updateStateSyncStatusIndexedBlock (queryRunner: QueryRunner, blockNumber: number, force?: boolean): Promise<StateSyncStatusInterface>