Skip to content

Commit

Permalink
Fix end overwrite of start
Browse files Browse the repository at this point in the history
  • Loading branch information
Inkvi committed Jul 23, 2024
1 parent 566f1c6 commit b38624a
Showing 1 changed file with 15 additions and 20 deletions.
35 changes: 15 additions & 20 deletions src/server-extension/resolvers/stats.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Arg, Field, ObjectType, Query, Resolver } from 'type-graphql'
import {
And,
And, Between,
Brackets,
EntityManager,
IsNull,
Expand Down Expand Up @@ -73,23 +73,18 @@ export class StatsResolver {
async getStat(name: StatName, chainId: number, start: number, end: number): Promise<Stat> {
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
Expand Down Expand Up @@ -157,11 +152,11 @@ export class StatsResolver {
@Query(() => BackfillStat)
async backfill(): Promise<BackfillStat> {
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: [
Expand All @@ -174,7 +169,7 @@ export class StatsResolver {
]
})
console.timeEnd("packetCatchupErrorsQuery");

console.time("channelsQuery");
let channels = await manager.getRepository(Channel).count({
relations: {
Expand All @@ -187,7 +182,7 @@ export class StatsResolver {
where: getMissingChannelMetricsClauses()
})
console.timeEnd("channelsQuery");

console.time("channelCatchupErrorsQuery");
let channelCatchupErrors = await manager.getRepository(ChannelCatchUpError).count({
where: [
Expand All @@ -203,7 +198,7 @@ export class StatsResolver {
]
})
console.timeEnd("channelCatchupErrorsQuery");

return {
channels,
packets,
Expand Down

0 comments on commit b38624a

Please sign in to comment.