return less data if long time frame
All checks were successful
deploy / deploy (push) Successful in 29s

This commit is contained in:
Lee 2023-10-27 16:16:07 +01:00
parent fbbf677667
commit 42485166bf

@ -11,7 +11,7 @@ const getPlayerHistoryQuery = `from(bucket: "${INFLUXDB_BUCKET}")
|> filter(fn: (r) => r["_measurement"] == "scoresaber")
|> filter(fn: (r) => r["_field"] == "value")
|> filter(fn: (r) => r["type"] == "player_count")
|> aggregateWindow(every: 1h, fn: mean)
|> aggregateWindow(every: {}, fn: mean)
|> yield()
`;
@ -29,9 +29,15 @@ app.get("/analytics", async (req, res) => {
error: "Time range too large. Max time range is 30 days.",
});
}
const shouldUseLongerIntervals = timeInMs > 24 * 60 * 60 * 1000 * 7; // 7 days
const rows = await InfluxQueryAPI.collectRows(
formatString(getPlayerHistoryQuery, false, timeQuery)
formatString(
getPlayerHistoryQuery,
false,
timeQuery,
shouldUseLongerIntervals ? "6h" : "1h"
)
);
let history = rows.map((row: any) => ({
time: row._time,