From cdb56f0740f43d654da174386c203c2bd1c64497 Mon Sep 17 00:00:00 2001 From: Mariano <9205080+marianososto@users.noreply.github.com> Date: Thu, 11 Jul 2024 15:52:29 -0300 Subject: [PATCH] hotfix for query chain-activity (#1543) --- api/handlers/transactions/repository.go | 32 +++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/api/handlers/transactions/repository.go b/api/handlers/transactions/repository.go index 740a7031..79e7d892 100644 --- a/api/handlers/transactions/repository.go +++ b/api/handlers/transactions/repository.go @@ -383,6 +383,38 @@ func (r *Repository) buildChainActivityQuery(q *ChainActivityQuery) string { } else { field = "count" } + + if q.TimeSpan == ChainActivityTs1Year || q.TimeSpan == ChainActivityTsAllTime { + + if field == "notional" { + field = "volume" + } + + var start string + measurement := "chain_activity_1d" + switch q.TimeSpan { + case ChainActivityTs1Year: + start = time.Now().AddDate(-1, 0, 0).Format(time.RFC3339) + case ChainActivityTsAllTime: + start = "1970-01-01T00:00:00Z" + default: + start = "1970-01-01T00:00:00Z" + } + + hotfixQuery := ` + import "date" + + from(bucket: "%s") + |> range(start: %s) + |> filter(fn: (r) => r._measurement == "%s") + |> filter(fn: (r) => r._field == "%s") + |> drop(columns:["_time","to","_measurement"]) + |> sum() +` + return fmt.Sprintf(hotfixQuery, r.bucketInfiniteRetention, start, measurement, field) + + } + var measurement string switch q.TimeSpan { case ChainActivityTs7Days: