feat(node): add GetNodeCount to get node count and remove no need node update log, only log when node count changed
Build / ubuntu-latest (push) Failing after 3m17s
Build / windows-latest (push) Canceled after 8m6s

This commit is contained in:
2026-09-29 21:43:46 +08:00
parent c7642ecca5
commit aa7e7f87e1
6 changed files with 23 additions and 9 deletions
+1 -1
View File
@@ -248,7 +248,7 @@ func (c *Client) FetchNodes() ([]NodeInfo, error) {
postLog.Warning("Failed to save bot node config: " + err.Error())
}
postLog.Info(fmt.Sprintf("Fetched %d nodes from Komari", len(nodes)))
// postLog.Debug(fmt.Sprintf("Fetched %d nodes from Komari", len(nodes)))
return nodes, nil
}
+10
View File
@@ -107,6 +107,7 @@ type StatusChangeCallback func(change StatusChange)
// All methods are thread-safe.
type Tracker struct {
mu sync.RWMutex
count int
nodes map[string]*Node // uuid → Node
uuidToName map[string]string // uuid → name (from node list)
onlineSet map[string]bool // which uuids are currently online
@@ -161,6 +162,13 @@ func (t *Tracker) fireCallbacks(change StatusChange) {
}
}
// GetNodeCount returns the total number of nodes in the tracker.
func (t *Tracker) GetNodeCount() int {
t.mu.RLock()
defer t.mu.RUnlock()
return t.count
}
// UpdateNodeList replaces the full node list and updates each node's name and
// static Info metadata. entries maps UUID → node metadata from the Komari node
// list.
@@ -175,6 +183,8 @@ func (t *Tracker) UpdateNodeList(entries map[string]NodeListEntry) {
t.knownUUIDs[uuid] = true
}
t.count = len(entries)
t.uuidToName = make(map[string]string, len(entries))
for uuid, entry := range entries {
t.uuidToName[uuid] = entry.Name