mirror of
https://github.com/cerc-io/watcher-ts
synced 2026-09-12 10:37:32 +00:00
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:
@@ -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')
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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, {});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user