Skip to content

Commit 463b800

Browse files
authored
📖 Included comments for the bfs on patchPlanning (#1130)
* [docs] Included comments for the bfs on patchPlanning * Included comments on SearchDependenciesFromStartNode Signed-off-by: nathannaveen <[email protected]> * Updated Based on Code Review Signed-off-by: nathannaveen <[email protected]> * Removed extra return value Signed-off-by: nathannaveen <[email protected]> * Updated based on code review Signed-off-by: nathannaveen <[email protected]> --------- Signed-off-by: nathannaveen <[email protected]>
1 parent 021655e commit 463b800

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

pkg/guacanalytics/patchPlanning.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,17 @@ func SearchDependentsFromStartPackage(ctx context.Context, gqlClient graphql.Cli
104104
q.queue = append(q.queue, startID)
105105
}
106106

107+
err = q.bfsOfDependents(ctx, gqlClient, stopID, maxDepth)
108+
if err != nil {
109+
return nil, nil, err
110+
}
111+
112+
return q.nodeMap, path, nil
113+
114+
}
115+
116+
// bfsOfDependents performs a breadth-first search on a graph to find dependencies
117+
func (q *queueValues) bfsOfDependents(ctx context.Context, gqlClient graphql.Client, stopID *string, maxDepth int) error {
107118
for len(q.queue) > 0 {
108119
q.now = &q.queue[0]
109120
q.queue = q.queue[1:]
@@ -117,26 +128,26 @@ func SearchDependentsFromStartPackage(ctx context.Context, gqlClient graphql.Cli
117128
break
118129
}
119130

131+
// model.Neighbors performs a GraphQL query to get the neighbor nodes of a given node.
120132
neighborsResponse, err := model.Neighbors(ctx, gqlClient, *q.now, []model.Edge{})
121133

122134
if err != nil {
123-
return nil, nil, fmt.Errorf("failed getting neighbors:%w", err)
135+
return fmt.Errorf("failed getting neighbors:%w", err)
124136
}
125137

126138
for _, neighbor := range neighborsResponse.Neighbors {
127-
err = caseOnPredicates(ctx, gqlClient, &q, neighbor, q.nowNode.Type)
139+
err = caseOnPredicates(ctx, gqlClient, q, neighbor, q.nowNode.Type)
128140

129141
if err != nil {
130-
return nil, nil, err
142+
return err
131143
}
132144
}
133145

134146
q.nowNode.Expanded = true
135147
q.nodeMap[*q.now] = q.nowNode
136148
}
137149

138-
return q.nodeMap, path, nil
139-
150+
return nil
140151
}
141152

142153
func caseOnPredicates(ctx context.Context, gqlClient graphql.Client, q *queueValues, neighbor model.NeighborsNeighborsNode, nodeType NodeType) error {

0 commit comments

Comments
 (0)