Skip to content

Commit

Permalink
chore: avoid using types in component_config_traverse
Browse files Browse the repository at this point in the history
  • Loading branch information
yashmehrotra committed Sep 25, 2024
1 parent c54756f commit c3aa861
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
11 changes: 5 additions & 6 deletions query/resource_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func SetResourceSelectorClause(ctx context.Context, resourceSelector types.Resou
if resourceSelector.Functions.ComponentConfigTraversal != nil {
args := resourceSelector.Functions.ComponentConfigTraversal
if table == "components" {
query = query.Where("id IN (SELECT id from lookup_component_config_id_related_components(?, ?, ?))", args.ComponentID, args.Direction, args.Types)
query = query.Where("id IN (SELECT id from lookup_component_config_id_related_components(?, ?))", args.ComponentID, args.Direction)
}
}

Expand All @@ -271,14 +271,13 @@ func setSearchQueryParams(rs *types.ResourceSelector) {

switch items[0] {
case "component_config_traverse":
// search: component_config_traverse=72143d48-da4a-477f-bac1-1e9decf188a6,outgoing,Kubernetes::Pod,Kubernetes::Node
// Args should be componentID, direction and types (compID,direction,type1,type2,type3)
args := strings.SplitN(items[1], ",", 3)
if len(args) == 3 {
// search: component_config_traverse=72143d48-da4a-477f-bac1-1e9decf188a6,outgoing
// Args should be componentID, direction and types (compID,direction)
args := strings.Split(items[1], ",")
if len(args) == 2 {
rs.Functions.ComponentConfigTraversal = &types.ComponentConfigTraversalArgs{
ComponentID: args[0],
Direction: args[1],
Types: types.Items(strings.Split(args[2], ",")),
}
}
case "id":
Expand Down
1 change: 0 additions & 1 deletion types/resource_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
type ComponentConfigTraversalArgs struct {
ComponentID string `yaml:"component_id,omitempty" json:"component_id,omitempty"`
Direction string `yaml:"direction,omitempty" json:"direction,omitempty"`
Types Items `yaml:"types,omitempty" json:"types,omitempty"`
}

type Functions struct {
Expand Down
6 changes: 2 additions & 4 deletions views/005_component_views.sql
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ CREATE OR REPLACE VIEW component_types AS

CREATE OR REPLACE FUNCTION lookup_component_config_id_related_components (
component_id TEXT,
type_filter TEXT DEFAULT 'outgoing',
component_types TEXT[] DEFAULT '{}'
type_filter TEXT DEFAULT 'outgoing'
)
RETURNS TABLE (id UUID) AS $$
BEGIN
Expand All @@ -165,7 +164,6 @@ BEGIN
)
SELECT components.id
FROM components
WHERE config_id IN (SELECT related_config_ids.id FROM related_config_ids)
AND type = ANY($3);
WHERE config_id IN (SELECT related_config_ids.id FROM related_config_ids);
END;
$$ LANGUAGE plpgsql;

0 comments on commit c3aa861

Please sign in to comment.