From 221118febcbff8fdb2ea0404b7774bff84774089 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 22 Nov 2025 15:59:49 +0000 Subject: [PATCH 1/3] Initial plan From d9f02d40546a081cbd7f764e4268f44da44b6dac Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 22 Nov 2025 16:02:20 +0000 Subject: [PATCH 2/3] Fix N+1 query issue by using hash lookup for target steps Co-authored-by: merefield <35533304+merefield@users.noreply.github.com> --- .../discourse_workflow/workflow_visualisation_controller.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/controllers/discourse_workflow/workflow_visualisation_controller.rb b/app/controllers/discourse_workflow/workflow_visualisation_controller.rb index eb74b7c..2189910 100644 --- a/app/controllers/discourse_workflow/workflow_visualisation_controller.rb +++ b/app/controllers/discourse_workflow/workflow_visualisation_controller.rb @@ -39,9 +39,12 @@ def network # Links: from each step via its options links = [] + # Build a hash of step_id => step to avoid N+1 queries + steps_by_id = steps.index_by(&:id) + steps.each do |step| step.workflow_step_options.each do |option| - target_step = DiscourseWorkflow::WorkflowStep.find(option.target_step_id) + target_step = steps_by_id[option.target_step_id] links << { source: step.name, From 9a6795e654f342bca1249ad03b24644589e6d828 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 22 Nov 2025 16:03:47 +0000 Subject: [PATCH 3/3] Add nil check for target_step to handle edge cases Co-authored-by: merefield <35533304+merefield@users.noreply.github.com> --- .../discourse_workflow/workflow_visualisation_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/discourse_workflow/workflow_visualisation_controller.rb b/app/controllers/discourse_workflow/workflow_visualisation_controller.rb index 2189910..c52af11 100644 --- a/app/controllers/discourse_workflow/workflow_visualisation_controller.rb +++ b/app/controllers/discourse_workflow/workflow_visualisation_controller.rb @@ -45,6 +45,7 @@ def network steps.each do |step| step.workflow_step_options.each do |option| target_step = steps_by_id[option.target_step_id] + next unless target_step # Skip if target step is not in this workflow links << { source: step.name,