perf: the remote-magpie follower reads providers.json's kept parse

KeepRemoteListsFollowed looks every minute (and on each write) for the
Remote magpies to follow, and followedMagpies parsed the whole of
providers.json again for it and normalized every provider in it. It now
reads storedFile, the parse kept until the file changes, and normalizes
only a provider that has an Anthropic address; what it returns is still
each provider's own normalized copy. In the tray-only profile this was
3 MB of the 11 MB providers.json decoding allocated over seven minutes.

Run: go test -race -run 'Follow|Remote' ./internal/provider on mote,
then the whole package.
This commit is contained in:
yetone
2026-11-14 15:36:16 +08:00
parent c8d47121b4
commit 79a30eb9cc
+12 -2
View File
@@ -115,10 +115,20 @@ func KeepRemoteListsFollowed(ctx context.Context) {
// followedMagpies are the Remote magpies whose lists are followed: on,
// listing, not this magpie itself, with a schedule (their user's, or
// RemoteMagpieEvery when none is set).
//
// Read from the parse kept until providers.json changes (storedFile), and
// only a provider with an Anthropic address normalized: this runs every
// minute, and parsing the whole file again each time was most of what an
// idle magpie allocated for providers.
func followedMagpies() []Provider {
own, _ := ownOf(load())
var out []Provider
for _, p := range own {
for _, p := range storedFile().Providers {
if strings.TrimSpace(p.Anthropic) == "" {
continue
}
if p = normalize(p); !hasEndpoint(p) {
continue
}
if p.IsRemoteMagpie() && !p.Off && p.lists() && p.Anthropic != "" && !p.SelfLeftOut() && p.RefreshInterval() > 0 {
out = append(out, p)
}