From 3346e572d296729091d8d0f33d6b80ebe4a729ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B2=D0=BE=D0=B2=20=D0=90=D1=80=D1=82?= =?UTF-8?q?=D0=B5=D0=BC?= Date: Sun, 21 Jun 2026 02:31:58 +0300 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=BA=D0=BE=D1=80=D1=80=D0=B5=D0=BA?= =?UTF-8?q?=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BB=20findBucketedRange.?= =?UTF-8?q?=20=D0=A3=D0=BF=D1=80=D0=BE=D1=81=D1=82=D0=B8=D0=BB=20sql=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=BF=D1=80=D0=BE=D1=81.=20=D0=A1=D0=BA=D0=BE?= =?UTF-8?q?=D1=80=D1=80=D0=B5=D0=BA=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D0=BB=20history.types?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/history/history.repository.ts | 23 ++++++++--------------- src/history/history.types.ts | 2 -- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/src/history/history.repository.ts b/src/history/history.repository.ts index 1fee3e1..e36592c 100644 --- a/src/history/history.repository.ts +++ b/src/history/history.repository.ts @@ -17,25 +17,18 @@ export class HistoryRepository { const result = await this.db.query( ` SELECT - $1::varchar AS edge, - $2::varchar AS tag, - bucket AS time, + time_bucket($5::interval, timestamp) AS time, min(value)::double precision AS min_value, avg(value)::double precision AS avg_value, max(value)::double precision AS max_value, count(*)::integer AS point_count - FROM ( - SELECT - time_bucket($5::interval, timestamp) AS bucket, - value - FROM history - WHERE edge = $1 - AND tag = $2 - AND timestamp >= $3 - AND timestamp < $4 - ) AS bucketed - GROUP BY bucket - ORDER BY bucket ASC + FROM history + WHERE edge = $1 + AND tag = $2 + AND timestamp >= $3 + AND timestamp < $4 + GROUP BY time + ORDER BY time ASC `, [edge, tag, from, to, granulate], ); diff --git a/src/history/history.types.ts b/src/history/history.types.ts index 470112b..5fcf7dc 100644 --- a/src/history/history.types.ts +++ b/src/history/history.types.ts @@ -1,6 +1,4 @@ export type HistoryRow = { - edge: string; - tag: string; time: Date; min_value: number; avg_value: number;