Don't draw edges on graph to non-existing entities.

This commit is contained in:
Andrey Smirnov
2014-02-26 19:39:19 +04:00
parent f643d3f04d
commit 2f30cf0846
+20 -3
View File
@@ -25,6 +25,8 @@ func aptlyGraph(cmd *commander.Command, args []string) error {
graph.SetDir(true) graph.SetDir(true)
graph.SetName("aptly") graph.SetName("aptly")
existingNodes := map[string]bool{}
fmt.Printf("Loading mirrors...\n") fmt.Printf("Loading mirrors...\n")
repoCollection := debian.NewRemoteRepoCollection(context.database) repoCollection := debian.NewRemoteRepoCollection(context.database)
@@ -43,6 +45,7 @@ func aptlyGraph(cmd *commander.Command, args []string) error {
repo.Name, repo.ArchiveRoot, repo.Distribution, strings.Join(repo.Components, ", "), repo.Name, repo.ArchiveRoot, repo.Distribution, strings.Join(repo.Components, ", "),
strings.Join(repo.Architectures, ", "), repo.NumPackages())), strings.Join(repo.Architectures, ", "), repo.NumPackages())),
}) })
existingNodes[repo.UUID] = true
return nil return nil
}) })
@@ -54,6 +57,11 @@ func aptlyGraph(cmd *commander.Command, args []string) error {
snapshotCollection := debian.NewSnapshotCollection(context.database) snapshotCollection := debian.NewSnapshotCollection(context.database)
snapshotCollection.ForEach(func(snapshot *debian.Snapshot) error {
existingNodes[snapshot.UUID] = true
return nil
})
err = snapshotCollection.ForEach(func(snapshot *debian.Snapshot) error { err = snapshotCollection.ForEach(func(snapshot *debian.Snapshot) error {
err := snapshotCollection.LoadComplete(snapshot) err := snapshotCollection.LoadComplete(snapshot)
if err != nil { if err != nil {
@@ -74,11 +82,17 @@ func aptlyGraph(cmd *commander.Command, args []string) error {
if snapshot.SourceKind == "repo" { if snapshot.SourceKind == "repo" {
for _, uuid := range snapshot.SourceIDs { for _, uuid := range snapshot.SourceIDs {
graph.AddEdge(graphvizEscape(uuid), "", graphvizEscape(snapshot.UUID), "", true, nil) _, exists := existingNodes[uuid]
if exists {
graph.AddEdge(graphvizEscape(uuid), "", graphvizEscape(snapshot.UUID), "", true, nil)
}
} }
} else if snapshot.SourceKind == "snapshot" { } else if snapshot.SourceKind == "snapshot" {
for _, uuid := range snapshot.SourceIDs { for _, uuid := range snapshot.SourceIDs {
graph.AddEdge(graphvizEscape(uuid), "", graphvizEscape(snapshot.UUID), "", true, nil) _, exists := existingNodes[uuid]
if exists {
graph.AddEdge(graphvizEscape(uuid), "", graphvizEscape(snapshot.UUID), "", true, nil)
}
} }
} }
return nil return nil
@@ -100,7 +114,10 @@ func aptlyGraph(cmd *commander.Command, args []string) error {
"label": graphvizEscape(fmt.Sprintf("{Published %s/%s|comp: %s|arch: %s}", repo.Prefix, repo.Distribution, repo.Component, strings.Join(repo.Architectures, ", "))), "label": graphvizEscape(fmt.Sprintf("{Published %s/%s|comp: %s|arch: %s}", repo.Prefix, repo.Distribution, repo.Component, strings.Join(repo.Architectures, ", "))),
}) })
graph.AddEdge(graphvizEscape(repo.SnapshotUUID), "", graphvizEscape(repo.UUID), "", true, nil) _, exists := existingNodes[repo.SnapshotUUID]
if exists {
graph.AddEdge(graphvizEscape(repo.SnapshotUUID), "", graphvizEscape(repo.UUID), "", true, nil)
}
return nil return nil
}) })