providers: with no account removed, Hidden makes no account

Hidden read every sign-in (Accounts: Codex, plugins, Claude...) and
then kept those the user removed. The Providers page asks it twice a
poll (directly and through Excluded), and most users removed none; the
real account has none, so ~0.6 MB a poll was made for an empty answer.
It now looks at the saved file first and returns nil when nothing in it
is hidden.

Measured on mote with the real account copy, 40 asks of
/api/providers (aalloc.sh, alloc_space delta): 169.8MB (v0.1.3447) ->
146.6MB, -14%. CPU for 30 asks (aeach.sh): 0.65s -> 0.56s.

Run: go vet ./internal/provider; go test -count=1 -timeout 45m
./internal/provider ./internal/gui (ok, ok) on mote. New
TestHiddenNoneMakesNoAccount fails with the check taken out by hand
(254 allocations, its accounts 249) and checks a removed account is
still listed. Not tried: Windows and Linux (no OS-specific code).
This commit is contained in:
yetone
2026-11-10 02:16:41 +08:00
parent e9b8b1c83e
commit a09e967f53
2 changed files with 27 additions and 0 deletions
@@ -46,3 +46,24 @@ func TestHiddenParsedOnceUntilTheFileChanges(t *testing.T) {
t.Fatalf("an account shown again since is still hidden: %+v", h)
}
}
// With no account removed, as for most users, Hidden makes no account:
// the Providers page asks it twice a poll, and reading every sign-in
// for an empty answer was ~0.6 MB of each poll's garbage.
func TestHiddenNoneMakesNoAccount(t *testing.T) {
home := claudeHome(t)
claudeSignIn(t, home, time.Now().Add(24*time.Hour))
writeFile(t, Path(), map[string]any{"providers": []map[string]any{{"id": "claude"}}})
Hidden()
accounts := testing.AllocsPerRun(10, func() { Accounts() })
if accounts == 0 {
t.Fatal("Accounts made nothing, so this test tells nothing")
}
if h := testing.AllocsPerRun(10, func() { Hidden() }); h >= accounts {
t.Errorf("Hidden with nothing removed made %.0f allocations, its accounts %.0f", h, accounts)
}
writeFile(t, Path(), map[string]any{"providers": []map[string]any{{"id": "claude", "hidden": true}}})
if h := Hidden(); len(h) != 1 || h[0].ID != "claude" {
t.Fatalf("a removed account: Hidden = %+v", h)
}
}
+6
View File
@@ -1075,6 +1075,12 @@ func accountSettings(a, pk Provider) Provider {
func Hidden() []Provider {
var out []Provider
saved := storedFile().Providers
// most users removed none: then no account is made at all (Accounts
// reads every sign-in, ~0.6 MB each poll of the Providers page,
// which asks twice, here and through Excluded)
if !slices.ContainsFunc(saved, func(p Provider) bool { return p.Hidden }) {
return nil
}
for _, a := range Accounts() {
for _, p := range saved {
if p.ID == a.ID && p.Hidden {