Avoid resorting multiple times
This commit is contained in:
parent
75388caeed
commit
6b46465c77
@ -315,10 +315,12 @@ func Load(rd io.Reader, myID protocol.NodeID) (Configuration, error) {
|
|||||||
// Ensure that any loose nodes are not present in the wrong places
|
// Ensure that any loose nodes are not present in the wrong places
|
||||||
// Ensure that there are no duplicate nodes
|
// Ensure that there are no duplicate nodes
|
||||||
cfg.Nodes = ensureNodePresent(cfg.Nodes, myID)
|
cfg.Nodes = ensureNodePresent(cfg.Nodes, myID)
|
||||||
|
sort.Sort(NodeConfigurationList(cfg.Nodes))
|
||||||
for i := range cfg.Repositories {
|
for i := range cfg.Repositories {
|
||||||
cfg.Repositories[i].Nodes = ensureNodePresent(cfg.Repositories[i].Nodes, myID)
|
cfg.Repositories[i].Nodes = ensureNodePresent(cfg.Repositories[i].Nodes, myID)
|
||||||
cfg.Repositories[i].Nodes = ensureExistingNodes(cfg.Repositories[i].Nodes, existingNodes)
|
cfg.Repositories[i].Nodes = ensureExistingNodes(cfg.Repositories[i].Nodes, existingNodes)
|
||||||
cfg.Repositories[i].Nodes = ensureNoDuplicates(cfg.Repositories[i].Nodes)
|
cfg.Repositories[i].Nodes = ensureNoDuplicates(cfg.Repositories[i].Nodes)
|
||||||
|
sort.Sort(NodeConfigurationList(cfg.Repositories[i].Nodes))
|
||||||
}
|
}
|
||||||
|
|
||||||
// An empty address list is equivalent to a single "dynamic" entry
|
// An empty address list is equivalent to a single "dynamic" entry
|
||||||
@ -383,23 +385,17 @@ func (l NodeConfigurationList) Len() int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ensureNodePresent(nodes []NodeConfiguration, myID protocol.NodeID) []NodeConfiguration {
|
func ensureNodePresent(nodes []NodeConfiguration, myID protocol.NodeID) []NodeConfiguration {
|
||||||
var myIDExists bool
|
|
||||||
for _, node := range nodes {
|
for _, node := range nodes {
|
||||||
if node.NodeID.Equals(myID) {
|
if node.NodeID.Equals(myID) {
|
||||||
myIDExists = true
|
return nodes
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !myIDExists {
|
|
||||||
name, _ := os.Hostname()
|
name, _ := os.Hostname()
|
||||||
nodes = append(nodes, NodeConfiguration{
|
nodes = append(nodes, NodeConfiguration{
|
||||||
NodeID: myID,
|
NodeID: myID,
|
||||||
Name: name,
|
Name: name,
|
||||||
})
|
})
|
||||||
}
|
|
||||||
|
|
||||||
sort.Sort(NodeConfigurationList(nodes))
|
|
||||||
|
|
||||||
return nodes
|
return nodes
|
||||||
}
|
}
|
||||||
@ -416,11 +412,7 @@ loop:
|
|||||||
}
|
}
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
nodes = nodes[0:count]
|
return nodes[0:count]
|
||||||
|
|
||||||
sort.Sort(NodeConfigurationList(nodes))
|
|
||||||
|
|
||||||
return nodes
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func ensureNoDuplicates(nodes []NodeConfiguration) []NodeConfiguration {
|
func ensureNoDuplicates(nodes []NodeConfiguration) []NodeConfiguration {
|
||||||
@ -438,9 +430,5 @@ loop:
|
|||||||
seenNodes[id] = true
|
seenNodes[id] = true
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
nodes = nodes[0:count]
|
return nodes[0:count]
|
||||||
|
|
||||||
sort.Sort(NodeConfigurationList(nodes))
|
|
||||||
|
|
||||||
return nodes
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user