Remove eventName filter in events count query (#220)

This commit is contained in:
nikugogoi 2022-11-10 12:09:17 +05:30 committed by GitHub
parent 3862f9ce2e
commit ecd8b2474a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 22 deletions

View File

@ -544,7 +544,7 @@ export class Database {
}
let entities = await selectQueryBuilder.getRawMany();
entities = await this._transformResults(queryRunner, repo.createQueryBuilder('subTable'), entities);
entities = await this.transformResults(queryRunner, repo.createQueryBuilder('subTable'), entities);
return entities as Entity[];
}
@ -670,7 +670,7 @@ export class Database {
}
let entities = await selectQueryBuilder.getRawMany();
entities = await this._transformResults(queryRunner, repo.createQueryBuilder('subTable'), entities);
entities = await this.transformResults(queryRunner, repo.createQueryBuilder('subTable'), entities);
return entities as Entity[];
}
@ -1185,7 +1185,7 @@ export class Database {
cachePrunedEntitiesCount.set(totalEntities);
}
async _transformResults<Entity> (queryRunner: QueryRunner, qb: SelectQueryBuilder<Entity>, rawResults: any[]): Promise<any[]> {
async transformResults<Entity> (queryRunner: QueryRunner, qb: SelectQueryBuilder<Entity>, rawResults: any[]): Promise<any[]> {
const transformer = new RawSqlResultsToEntityTransformer(
qb.expressionMap,
queryRunner.manager.connection.driver,

View File

@ -71,8 +71,6 @@ export class Database {
_config: ConnectionOptions
_conn!: Connection
_pgPool: Pool
_blockCount = 0
_eventCount = 0
constructor (config: ConnectionOptions) {
assert(config);
@ -181,8 +179,7 @@ export class Database {
}
async saveBlockProgress (repo: Repository<BlockProgressInterface>, block: DeepPartial<BlockProgressInterface>): Promise<BlockProgressInterface> {
this._blockCount++;
blockProgressCount.set(this._blockCount);
blockProgressCount.inc(1);
return await repo.save(block);
}
@ -275,8 +272,7 @@ export class Database {
});
const blockProgress = await blockRepo.save(entity);
this._blockCount++;
blockProgressCount.set(this._blockCount);
blockProgressCount.inc(1);
// Bulk insert events.
events.forEach(event => {
@ -301,8 +297,8 @@ export class Database {
});
await Promise.all(insertPromises);
this._eventCount += events.filter(event => event.eventName !== UNKNOWN_EVENT_NAME).length;
eventCount.set(this._eventCount);
const knownEvents = events.filter(event => event.eventName !== UNKNOWN_EVENT_NAME).length;
eventCount.inc(knownEvents);
}
async getEntities<Entity> (queryRunner: QueryRunner, entity: new () => Entity, findConditions?: FindManyOptions<Entity>): Promise<Entity[]> {
@ -411,8 +407,7 @@ export class Database {
async saveEventEntity (repo: Repository<EventInterface>, entity: EventInterface): Promise<EventInterface> {
const event = await repo.save(entity);
this._eventCount++;
eventCount.set(this._eventCount);
eventCount.inc(1);
return event;
}
@ -869,20 +864,16 @@ export class Database {
}
async _fetchBlockCount (): Promise<void> {
this._blockCount = await this._conn.getRepository('block_progress')
const res = await this._conn.getRepository('block_progress')
.count();
blockProgressCount.set(this._blockCount);
blockProgressCount.set(res);
}
async _fetchEventCount (): Promise<void> {
this._eventCount = await this._conn.getRepository('event')
.count({
where: {
eventName: Not(UNKNOWN_EVENT_NAME)
}
});
const res = await this._conn.getRepository('event')
.count();
eventCount.set(this._eventCount);
eventCount.set(res);
}
}