Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
web
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
KiangWuHospital
web
Commits
1fa47b9d
Commit
1fa47b9d
authored
Oct 26, 2026
by
久林
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 修复 timeseries 合并损坏导致服务端无法启动
Co-authored-by: Cursor <cursoragent@cursor.com>
parent
e3b335fb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
36 deletions
+36
-36
server/src/db/timeseries.ts
+36
-36
No files found.
server/src/db/timeseries.ts
View file @
1fa47b9d
...
...
@@ -362,7 +362,7 @@ export function resolveTsTimeRange(opts: {
}
if
(
toMs
-
fromMs
>
maxMs
)
{
throw
new
Error
(
查询跨度不能超过
天
)
throw
new
Error
(
`查询跨度不能超过
${
maxHistorySpanDays
()}
天`
)
}
if
(
toMs
-
fromMs
<
60
_000
)
{
throw
new
Error
(
'查询跨度至少 1 分钟'
)
...
...
@@ -436,7 +436,7 @@ export async function queryTsSeries(opts: {
let
deviceFilter
=
''
if
(
opts
.
deviceIds
?.
length
)
{
params
.
push
(
opts
.
deviceIds
)
deviceFilter
=
AND
device_id
=
ANY
({
params
.
length
}::
text
[])
deviceFilter
=
` AND device_id = ANY($
${
params
.
length
}
::text[])`
}
let
{
rows
:
rollupRows
}
=
await
query
<
{
...
...
@@ -444,12 +444,12 @@ export async function queryTsSeries(opts: {
bucket
:
Date
avg_eng
:
string
|
number
}
>
(
SELECT
device_id
,
bucket
,
avg_eng
`
SELECT device_id, bucket, avg_eng
FROM ts_rollups
WHERE
source
=
AND
metric
=
AND
bucket_minutes
=
AND
bucket
>=
AND
bucket
<=
ORDER
BY
device_id
,
bucket
,
WHERE source =
$1 AND metric = $2 AND bucket_minutes = $5
AND bucket >=
$3 AND bucket <= $4
${
deviceFilter
}
ORDER BY device_id, bucket
`
,
params
,
)
...
...
@@ -460,19 +460,19 @@ export async function queryTsSeries(opts: {
let
fbFilter
=
''
if
(
opts
.
deviceIds
?.
length
)
{
fbParams
.
push
(
opts
.
deviceIds
)
fbFilter
=
AND
device_id
=
ANY
({
fbParams
.
length
}::
text
[])
fbFilter
=
` AND device_id = ANY($
${
fbParams
.
length
}
::text[])`
}
const
fallback
=
await
query
<
{
device_id
:
string
bucket
:
Date
avg_eng
:
string
|
number
}
>
(
SELECT
device_id
,
bucket
,
avg_eng
`
SELECT device_id, bucket, avg_eng
FROM ts_rollups
WHERE
source
=
AND
metric
=
AND
bucket_minutes
=
AND
bucket
>=
AND
bucket
<=
ORDER
BY
device_id
,
bucket
,
WHERE source =
$1 AND metric = $2 AND bucket_minutes = $5
AND bucket >=
$3 AND bucket <= $4
${
fbFilter
}
ORDER BY device_id, bucket
`
,
fbParams
,
)
if
(
fallback
.
rows
.
length
)
{
...
...
@@ -488,12 +488,12 @@ export async function queryTsSeries(opts: {
bucket
:
Date
avg_eng
:
string
|
number
}
>
(
SELECT
device_id
,
bucket
,
avg_eng
`
SELECT device_id, bucket, avg_eng
FROM ts_rollups
WHERE
source
=
AND
metric
=
AND
bucket_minutes
=
15
AND
bucket
>=
AND
bucket
<=
ORDER
BY
device_id
,
bucket
,
WHERE source =
$1 AND metric = $2
AND bucket_minutes = 15
AND bucket >=
$3 AND bucket <= $4
${
deviceFilter
}
ORDER BY device_id, bucket
`
,
params
,
)
rollupRows
=
fallback
.
rows
...
...
@@ -510,16 +510,16 @@ export async function queryTsSeries(opts: {
bucket
:
Date
avg_eng
:
string
|
number
}
>
(
SELECT
`
SELECT
device_id,
to_timestamp
(
floor
(
extract
(
epoch
FROM
ts
)
/
(
*
60
))
*
(
*
60
))
AS
bucket
,
to_timestamp(floor(extract(epoch FROM ts) / (
$5 * 60)) * ($5
* 60)) AS bucket,
AVG(eng) AS avg_eng
FROM ts_samples
WHERE
source
=
AND
metric
=
AND
ts
>=
AND
ts
<=
WHERE source =
$1 AND metric = $2
AND ts >=
$3 AND ts <= $4
${
deviceFilter
}
GROUP BY device_id, bucket
ORDER
BY
device_id
,
bucket
,
ORDER BY device_id, bucket
`
,
params
,
)
...
...
@@ -557,7 +557,7 @@ export async function queryTsExportRows(opts: {
let
deviceFilter
=
''
if
(
opts
.
deviceIds
?.
length
)
{
params
.
push
(
opts
.
deviceIds
)
deviceFilter
=
AND
device_id
=
ANY
({
params
.
length
}::
text
[])
deviceFilter
=
` AND device_id = ANY($
${
params
.
length
}
::text[])`
}
const
{
rows
:
raw
}
=
await
query
<
{
...
...
@@ -568,13 +568,13 @@ export async function queryTsExportRows(opts: {
eng
:
string
|
number
raw
:
string
|
number
|
null
}
>
(
SELECT
ts
,
device_id
,
source
,
metric
,
eng
,
raw
`
SELECT ts, device_id, source, metric, eng, raw
FROM ts_samples
WHERE
source
=
AND
metric
=
AND
ts
>=
AND
ts
<=
WHERE source =
$1 AND metric = $2
AND ts >=
$3 AND ts <= $4
${
deviceFilter
}
ORDER BY device_id, ts
LIMIT
,
LIMIT
$5`
,
params
,
)
...
...
@@ -602,7 +602,7 @@ export async function queryTsExportRows(opts: {
let
rollDeviceFilter
=
''
if
(
opts
.
deviceIds
?.
length
)
{
rollParams
.
push
(
opts
.
deviceIds
)
rollDeviceFilter
=
AND
device_id
=
ANY
({
rollParams
.
length
}::
text
[])
rollDeviceFilter
=
` AND device_id = ANY($
${
rollParams
.
length
}
::text[])`
}
rollParams
.
push
(
EXPORT_ROW_LIMIT
+
1
)
const
limitIdx
=
rollParams
.
length
...
...
@@ -613,13 +613,13 @@ export async function queryTsExportRows(opts: {
metric
:
string
avg_eng
:
string
|
number
}
>
(
SELECT
bucket
,
device_id
,
source
,
metric
,
avg_eng
`
SELECT bucket, device_id, source, metric, avg_eng
FROM ts_rollups
WHERE
source
=
AND
metric
=
AND
bucket_minutes
=
AND
bucket
>=
AND
bucket
<=
WHERE source =
$1 AND metric = $2 AND bucket_minutes = $5
AND bucket >=
$3 AND bucket <= $4
${
rollDeviceFilter
}
ORDER BY device_id, bucket
LIMIT
{
limitIdx
}
,
LIMIT
$
${
limitIdx
}
`
,
rollParams
,
)
if
(
!
roll
.
length
)
continue
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment