From a09e967f53a7776f3139b71dfb2e740bba755bfb Mon Sep 17 00:00:00 2001 From: yetone Date: Tue, 10 Nov 2026 02:16:37 +0800 Subject: [PATCH] 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). --- internal/provider/hidden_parsed_once_test.go | 21 ++++++++++++++++++++ internal/provider/provider.go | 6 ++++++ 2 files changed, 27 insertions(+) diff --git a/internal/provider/hidden_parsed_once_test.go b/internal/provider/hidden_parsed_once_test.go index d1a33bc99..4b7ba4076 100644 --- a/internal/provider/hidden_parsed_once_test.go +++ b/internal/provider/hidden_parsed_once_test.go @@ -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) + } +} diff --git a/internal/provider/provider.go b/internal/provider/provider.go index cc5d0db75..e2bc6452e 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -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 {