console: fix intermittent failure when requesting previous period

Notably when the main table is required, but also on rare conditions
when another table would be selected because of the interval selection.

This is not perfect as sometimes, we won't have the data.
This commit is contained in:
Vincent Bernat
2025-07-16 20:46:35 +02:00
parent d3d80c1dbf
commit 5e826d48b1
5 changed files with 81 additions and 21 deletions

View File

@@ -215,19 +215,18 @@ func (c *Component) contextFunc(inputStr string) context {
func (c *Component) computeTableAndInterval(input inputContext) (string, time.Duration, time.Duration) {
targetInterval := time.Duration(uint64(input.End.Sub(input.Start)) / uint64(input.Points))
if targetInterval < time.Second {
targetInterval = time.Second
}
targetInterval = max(targetInterval, time.Second)
// Select table
targetIntervalForTableSelection := targetInterval
if input.MainTableRequired {
targetIntervalForTableSelection = time.Second
}
table, computedInterval := c.getBestTable(input.Start, targetIntervalForTableSelection)
startForTableSelection := input.Start
if input.StartForInterval != nil {
_, computedInterval = c.getBestTable(*input.StartForInterval, targetIntervalForTableSelection)
startForTableSelection = *input.StartForInterval
}
table, computedInterval := c.getBestTable(startForTableSelection, targetIntervalForTableSelection)
return table, computedInterval, targetInterval
}