Files
yetone d7796bf409 usage: a day card's switch builds one page, not one per agent
WaiooT on X: "每日用量卡,切换日期的时候,账单计算很卡". The day-card
page's usage:day read is usageapi.SpanOf. For each date it built the
day's page, then one more page of the same day for every agent (up to
12) only to read that agent's By["modelAt"], and every one of those
builds listed and stat'd every agent session file again
(readRequestState). A switch to an older day misses the request-page
cache (16 pages), so it paid all of them each time.

- RequestPage.AgentModels: each agent's By["modelAt"], counted in the
  same cell pass as By (cellGroup bit of modelAt, keyed by ReportedAs as
  a filter's Agent is), and from the ledger's rows on the LogCalls path.
  SpanOf reads it in place of a page per agent. The calls that named no
  agent are still listed by model only when they are all there are.
- SpanOf holds sessions.OneListing() for its reads, as the sessions
  overview and stats handlers do, so the session folders are listed once
  a read.

Measured on mote (a throwaway test, not committed: 401,502 gateway
records over 365 days in 6 agents x 6 providers, plus 20 Claude Code
session files a day of 60 calls each, half mirrored by gateway records),
origin/main 6ac19f4bc against this:
- switch to a past day: 243-300ms -> 32-48ms
- today again after it: 57-94ms -> 20-28ms
- 7-day span 400ms -> 44ms, 30-day 1.17s -> 91ms, all time 12.3s -> 2.2s
- 30 switches back a day each (180-day ledger): 4.0-4.9s -> 0.87s
The CPU profile before: readRequestState 46%, then the per-agent builds.

TestAgentModelsAreEachAgentsPage holds AgentModels to the page of
each agent, for a whole week and for a day in it, on the cells path and
the ledger path. Broken by hand: counting from the chart's bits (the
whole period) goes red on cells; the whole ledger in place of the
filter's rows goes red on ledger. Keying by the raw agent instead of
ReportedAs stays green: rows carry the reported name already, and only a
renamed client could tell the two apart.
2026-11-19 18:09:56 +08:00
..