From fb5d4818b023f9b2229293bf77f99c8b77b1618d Mon Sep 17 00:00:00 2001 From: Alliot <24980252+AlliotTech@users.noreply.github.com> Date: Sun, 22 Feb 2026 13:04:33 +0800 Subject: [PATCH] fix: page smart attribute queries with limit and sort (#869) --- .../scrutiny_repository_device_smart_attributes.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/webapp/backend/pkg/database/scrutiny_repository_device_smart_attributes.go b/webapp/backend/pkg/database/scrutiny_repository_device_smart_attributes.go index 96bbad0..b9db103 100644 --- a/webapp/backend/pkg/database/scrutiny_repository_device_smart_attributes.go +++ b/webapp/backend/pkg/database/scrutiny_repository_device_smart_attributes.go @@ -177,7 +177,7 @@ func (sr *scrutinyRepository) aggregateSmartAttributesQuery(wwn string, duration `|> sort(columns: ["_time"], desc: true)`, }...) if selectEntries > 0 { - partialQueryStr = append(partialQueryStr, fmt.Sprintf(`|> tail(n: %d, offset: %d)`, selectEntries, selectEntriesOffset)) + partialQueryStr = append(partialQueryStr, fmt.Sprintf(`|> limit(n: %d, offset: %d)`, selectEntries, selectEntriesOffset)) } partialQueryStr = append(partialQueryStr, `|> yield(name: "last")`) @@ -196,9 +196,11 @@ func (sr *scrutinyRepository) generateSmartAttributesSubquery(wwn string, durati } partialQueryStr = append(partialQueryStr, `|> aggregateWindow(every: 1d, fn: last, createEmpty: false)`) - + + // ensure we are selecting the latest entries when paging + partialQueryStr = append(partialQueryStr, `|> sort(columns: ["_time"], desc: true)`) if selectEntries > 0 { - partialQueryStr = append(partialQueryStr, fmt.Sprintf(`|> tail(n: %d, offset: %d)`, selectEntries, selectEntriesOffset)) + partialQueryStr = append(partialQueryStr, fmt.Sprintf(`|> limit(n: %d, offset: %d)`, selectEntries, selectEntriesOffset)) } partialQueryStr = append(partialQueryStr, "|> schema.fieldsAsCols()")