feat(gateway): update Flux query to retrieve data from the last day
Signed-off-by: Klagarge <remi@heredero.ch>
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user