Skip to content

perf(api): /api/status re-integrates today's history on every poll #1145

Open

Description

@frahlg

GET /api/status re-integrates today's history (and the current 15-minute slot) on every 2s dashboard poll. That walks the same hot-tier rows the control tick is writing.

Found on master 6eadec3f. Still true on DuckDB PR #1129: the SQL moved engines, the poll did not.

What happens

d, err := s.deps.State.DailyEnergy(midnight.UnixMilli(), now.UnixMilli())

plus currentGridEnergySlot → another DailyEnergy. The query is UNION ALL of history_hot/warm/cold with LAG (go/internal/state/store.go). Late day at a 2s tick is tens of thousands of hot rows, every poll, concurrent with the writer.

Closed days already hit energy_daily. Today always recomputes. The comment at the handler already records a Pi stall when rows were shipped to Go; the SQL aggregate still visits the same rows.

#882 is the tick-writer side. This is the read side.

What a fix needs

  • Cache today's running totals between ticks, or increment from the last sample, so /api/status is O(1) or O(new samples).
  • Keep the existing "no interval yet after midnight → omit totals" guard.
  • Test: many hot rows, repeated DailyEnergy for today, then a status poll that does not rescan the whole day.
  • If this lands after feat(storage): use embedded DuckDB for primary history #1129, implement it on DuckDB, not by adding SQLite load.

Related: #882, #1129, and the history points cap.

Activity

  1. added
    enhancement
    on Sep 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions