Eliminate nodes with blank ID from results

Blank ID indicates something has gone wrong, maybe in delta generation.
If there are many nodes with blank ID then the mapping stage consumes
lots of CPU, so eliminate the possibility when results are collected.
This commit is contained in:
Bryan Boreham
2021-04-22 21:14:31 +00:00
parent 4e2f364381
commit 7e944fcac4

View File

@@ -185,6 +185,9 @@ func (ret *joinResults) mapChild(from, to string) {
// Add m into the results as a top-level node, mapped from original ID
// Note it is not safe to mix calls to add() with addChild(), addChildAndChildren() or addUnmappedChild()
func (ret *joinResults) add(from string, m report.Node) {
if from == "" || m.ID == "" {
return // this means something has gone wrong; don't let it pollute the results.
}
if existing, ok := ret.nodes[m.ID]; ok {
m = m.Merge(existing)
}
@@ -210,12 +213,18 @@ func (ret *joinResults) addUnmappedChild(m report.Node, id string, topology stri
// the specified topology if not already there, and updating the
// mapping from old ID to new ID.
func (ret *joinResults) addChild(m report.Node, id string, topology string) {
if id == "" || m.ID == "" {
return // this means something has gone wrong; don't let it pollute the results.
}
ret.addUnmappedChild(m, id, topology)
ret.mapChild(m.ID, id)
}
// Like addChild, but also add m's children.
func (ret *joinResults) addChildAndChildren(m report.Node, id string, topology string) {
if id == "" || m.ID == "" {
return // this means something has gone wrong; don't let it pollute the results.
}
ret.addUnmappedChild(m, id, topology)
result := ret.nodes[id]
result.Children.UnsafeMerge(m.Children)
@@ -225,6 +234,9 @@ func (ret *joinResults) addChildAndChildren(m report.Node, id string, topology s
// Add a copy of n straight into the results
func (ret *joinResults) passThrough(n report.Node) {
if n.ID == "" {
return // this means something has gone wrong; don't let it pollute the results.
}
n.Adjacency = nil // result() assumes all nodes start with no adjacencies
ret.nodes[n.ID] = n
n.Children = n.Children.Copy() // so we can do unsafe adds