Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,10 @@ def network
# Preload steps + options (and their workflow_option) to avoid extra queries when iterating
steps = workflow.workflow_steps.order(:position).includes(workflow_step_options: :workflow_option)

# Build a hash of category_id => category to avoid N+1 queries
category_ids = steps.filter_map(&:category_id).uniq
# Build category lookup hash to avoid N+1 queries
category_ids = steps.map(&:category_id).compact.uniq
categories_by_id = Category.where(id: category_ids).index_by(&:id)

# Build a hash of step_id => step for quick lookups in links
steps_by_id = steps.index_by(&:id)

# Lanes: unique categories in order of step position
lanes = steps.map do |step|
category = categories_by_id[step.category_id]
Expand Down