Commit Graph
1 Commits
Author SHA1 Message Date
wizzy-yangandwizzy-yang 7cba95b13d gui: a save shares one build of the catalog, not one per look-up (#908)
Saving a routing group took about 2.4s on a machine with 20 providers and
95 models. The save is not slow: the state it answers with is. groupsState
asks every group for its members and every model for its facts, and the
held middleware let only GET share one build of the catalog
(provider.Hold), so each of those look-ups built it again — 20 builds in
one save here, each reading every provider's files and every agent's
sign-in.

The Routing page's own 25s trace long-poll is a GET, so it usually holds
the catalog and the save costs ~140ms. Whenever it is not in flight — the
first save after the page loads, or between two polls — the save falls
back to the full 2.4s.

A write shares the build now. It is safe because every write drops what is
held as it happens: provider.store ends in catalog.Touched, and
catalog.Forget is Changed (provider/hold.go), while settings.Save calls
catalog.Forget itself. So a save still answers with the state after the
write, never the one before it, and the request leaves nothing held for
the next. Reads are unchanged.

TestSaveSharesOneCatalogBuild counts the builds one save makes
(provider.AllBuilt: 20 before, 2 after) and checks the answer is the state
just written — the group saved, renamed, deleted. TestAgentWriteAnsweredAs
Written covers the one path a write does not drop the catalog on,
agent.Apply (it writes an agent's config and never calls
catalog.Touched): the field it wrote is in the answer that POST returns.

POST /api/groups/save, the same group of 6 members (5 of them groups),
same config, same machine: 2452, 2659, 2388, 2333, 2308ms before
(median 2388ms), 1650, 138, 127, 124, 137ms after (median 137ms; the first
is the cold start). go vet, go build and go build -tags nogui pass.
TestGatewayFixQuitsOnlyAMagpie and TestPurposeAssetMatchesUsage fail on
unmodified main here too (a running magpie on the port, a stale generated
catalog), so they are not this change's.

Co-authored-by: wizzy-yang <wizzy-yang@users.noreply.github.com>
2026-10-05 21:42:15 +08:00