From b38624a3a6946a7adc7b1098157c3396d082ef11 Mon Sep 17 00:00:00 2001 From: Alexander Date: Tue, 23 Jul 2024 14:02:17 -0400 Subject: [PATCH] Fix end overwrite of start --- src/server-extension/resolvers/stats.ts | 35 +++++++++++-------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/src/server-extension/resolvers/stats.ts b/src/server-extension/resolvers/stats.ts index cbec188..1cadb31 100644 --- a/src/server-extension/resolvers/stats.ts +++ b/src/server-extension/resolvers/stats.ts @@ -1,6 +1,6 @@ import { Arg, Field, ObjectType, Query, Resolver } from 'type-graphql' import { - And, + And, Between, Brackets, EntityManager, IsNull, @@ -73,23 +73,18 @@ export class StatsResolver { async getStat(name: StatName, chainId: number, start: number, end: number): Promise { const manager = await this.tx() - let where = {} - if (chainId) { - where = {chainId} - } + let where: any = {} - if (start) { - where = { - ...where, - blockTimestamp: MoreThanOrEqual(start) - } + if (chainId) { + where.chainId = chainId } - if (end) { - where = { - ...where, - blockTimestamp: LessThanOrEqual(end) - } + if (start && end) { + where.blockTimestamp = Between(start, end) + } else if (start) { + where.blockTimestamp = MoreThanOrEqual(start) + } else if (end) { + where.blockTimestamp = LessThanOrEqual(end) } let val: number = 0 @@ -157,11 +152,11 @@ export class StatsResolver { @Query(() => BackfillStat) async backfill(): Promise { const manager = await this.tx() - + console.time("packetsQuery"); const packets = await manager.getRepository(Packet).count({where: getMissingPacketMetricsClauses()}) console.timeEnd("packetsQuery"); - + console.time("packetCatchupErrorsQuery"); let packetCatchupErrors = await manager.getRepository(PacketCatchUpError).count({ where: [ @@ -174,7 +169,7 @@ export class StatsResolver { ] }) console.timeEnd("packetCatchupErrorsQuery"); - + console.time("channelsQuery"); let channels = await manager.getRepository(Channel).count({ relations: { @@ -187,7 +182,7 @@ export class StatsResolver { where: getMissingChannelMetricsClauses() }) console.timeEnd("channelsQuery"); - + console.time("channelCatchupErrorsQuery"); let channelCatchupErrors = await manager.getRepository(ChannelCatchUpError).count({ where: [ @@ -203,7 +198,7 @@ export class StatsResolver { ] }) console.timeEnd("channelCatchupErrorsQuery"); - + return { channels, packets,