Skip to content

Commit

Permalink
refactor: reduce repetition in edge calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenHulme committed Jan 23, 2024
1 parent 49545cb commit c6af732
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions app/controllers/pipelines_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,36 @@ def calculate_pipelines
Settings.pipelines.map { |pl| { name: pl.name, filters: pl.filters } }
end

def calculate_edges_with_pipeline_data
Settings.pipelines.flat_map { |pl| pl.relationships.map { |s, t| { source: s, target: t, pipeline: pl } } }
end

def calculate_pipeline_edges
Settings.pipelines.flat_map do |pl|
pl.relationships.map do |s, t|
{ group: 'edges', data: { id: SecureRandom.uuid, source: s, target: t, pipeline: pl.name } }
end
calculate_edges_with_pipeline_data.map do |edge|
{
group: 'edges',
data: {
id: SecureRandom.uuid,
source: edge[:source],
target: edge[:target],
pipeline: edge[:pipeline].name
}
}
end
end

def calculate_group_edges
edges =
Settings.pipelines.flat_map do |pl|
pl.relationships.map do |s, t|
{ group: 'edges', data: { id: SecureRandom.uuid, source: s, target: t, group: pl.pipeline_group } }
end
end
edges.uniq { |e| e[:data][:source] + e[:data][:target] + e[:data][:group] }
calculate_edges_with_pipeline_data.map do |edge|
{
group: 'edges',
data: {
id: SecureRandom.uuid,
source: edge[:source],
target: edge[:target],
group: edge[:pipeline].pipeline_group
}
}
end
end

def calculate_edges
Expand Down

0 comments on commit c6af732

Please sign in to comment.