feat(node): add GetNodeCount to get node count and remove no need node update log, only log when node count changed
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user