feat(gateway): update Flux query to retrieve data from the last day

Signed-off-by: Klagarge <remi@heredero.ch>
This commit is contained in:
2025-06-08 17:52:44 +02:00
parent 44e11c8065
commit 11ca9dc51f

View File

@@ -63,13 +63,12 @@ func (gh *Gateway) requestInflux(c *gin.Context) error {
// The Flux query uses a large range (-1000d) and aggregates the latest values.
// This ensures we always get the most recent data, even if the database contains old entries.
query := fmt.Sprintf(`from(bucket: %q)
|> range(start: -1000d)
|> range(start: -1d)
|> filter(fn: (r) => r["_measurement"] == %q)
|> filter(fn: (r) => r["user"] == %q)
|> filter(fn: (r) => r["room"] == %q)
|> filter(fn: (r) => r["device"] == %q)
|> sort(columns: ["_time"], desc: true)
|> limit(n: 100)
`, INFLUXDB_BUCKET, MEASUREMENT_NAME, user, room, device)
results, err := queryAPI.Query(context.Background(), query)
if err != nil {