mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-28 09:41:57 +00:00
optimization: generate children counts on demand
Accumulating counts in the Node data structure takes a lot of effort, and it turns out we only use this information in a few places where it's easy to compute.
This commit is contained in:
@@ -71,8 +71,11 @@ func fromSets(n Node, key string) (string, bool) {
|
||||
}
|
||||
|
||||
func fromCounters(n Node, key string) (string, bool) {
|
||||
val, ok := n.LookupCounter(key)
|
||||
return strconv.Itoa(val), ok
|
||||
val := n.CountChildrenOfTopology(key)
|
||||
if val == 0 {
|
||||
return "", false
|
||||
}
|
||||
return strconv.Itoa(val), true
|
||||
}
|
||||
|
||||
// MetadataRow is a row for the metadata table.
|
||||
|
||||
@@ -100,6 +100,17 @@ func (n Node) AddCounter(k string, value int) Node {
|
||||
return n.WithLatest(name, mtime.Now(), strconv.Itoa(value))
|
||||
}
|
||||
|
||||
// CountChildrenOfTopology returns how many children have a particular topology
|
||||
func (n Node) CountChildrenOfTopology(topology string) int {
|
||||
count := 0
|
||||
for _, childID := range n.ChildIDs {
|
||||
if ty, ok := NodeIDType(childID); ok && ty == topology {
|
||||
count++
|
||||
}
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
// WithSet returns a fresh copy of n, with set merged in at key.
|
||||
func (n Node) WithSet(key string, set StringSet) Node {
|
||||
n.Sets = n.Sets.Add(key, set)
|
||||
|
||||
Reference in New Issue
Block a user