Files
magpie/internal/cli/account_discovery_cli.go
T
yetone 667ac8bd6f settings: a look at one setting takes the shared settings, not a copy
settings.Load() copies the whole Settings (clone + deepCopy of every map
and slice) for each caller. 133 places read one field of it and threw
the rest away: the proxy for every outgoing request (netproxy), the
GitHub token, the China mirror switch, a model's output cap, wire or
price on a gateway request. With a real account in the tray, Load's
clone was 26.6 MB of the 318 MB the process allocated in its first
seven minutes, most of it through netproxy.For on each request.

Each of them now reads settings.Shared(), the read-only settings every
caller is given for the same settings.json. Only reads were changed:
a scalar field (string, bool, int, float) or a map field's index
read. A caller that keeps a whole map or slice, or calls a method on
the settings, still takes Load's copy.
2026-11-14 14:02:49 +08:00

36 lines
1.2 KiB
Go

package cli
import (
"fmt"
"github.com/yetone/magpie/internal/provider"
"github.com/yetone/magpie/internal/settings"
)
// accountsDiscoveryCmd is `magpie accounts discovery [on|off]` (#1535):
// whether magpie reads the agents' own sign-ins (their credential files,
// the Keychain) and serves them as subscriptions; Settings → Privacy's
// Subscription accounts. With no argument it says which is in effect.
func accountsDiscoveryCmd(args []string) error {
if len(args) > 1 || len(args) == 1 && args[0] != "on" && args[0] != "off" {
return fmt.Errorf("usage: magpie accounts discovery [on|off]")
}
if len(args) == 1 {
s := settings.Load()
s.NoAccountDiscovery = args[0] == "off"
if err := settings.Save(s); err != nil {
return err
}
provider.ForgetAccounts()
}
switch {
case !settings.AccountDiscoveryOff():
fmt.Println("account discovery is on: magpie reads your agents' sign-ins and serves them as subscriptions")
case settings.Shared().NoAccountDiscovery:
fmt.Println("account discovery is off: magpie reads none of your agents' sign-ins and serves no subscription; API-key providers work as before")
default:
fmt.Println("account discovery is off for this run: MAGPIE_NO_ACCOUNTS is set (saved: on)")
}
return nil
}