From 327909395e63c276229e8e32e018b9a593a11590 Mon Sep 17 00:00:00 2001 From: soaxelbrooke Date: Wed, 16 Jul 2025 19:22:03 -0700 Subject: [PATCH] Fix mermaid edge duplication --- databuild/service/mermaid_utils.rs | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/databuild/service/mermaid_utils.rs b/databuild/service/mermaid_utils.rs index df54ba9..79f9d2a 100644 --- a/databuild/service/mermaid_utils.rs +++ b/databuild/service/mermaid_utils.rs @@ -89,6 +89,7 @@ pub fn generate_mermaid_with_status( // Track nodes we've already added to avoid duplicates let mut added_nodes = HashSet::new(); let mut added_refs = HashSet::new(); + let mut added_edges = HashSet::new(); // Map to track which refs are outputs (to highlight them) let mut is_output_ref = HashSet::new(); @@ -152,12 +153,21 @@ pub fn generate_mermaid_with_status( added_refs.insert(ref_node_id.clone()); } - // Add the edge from input to job - if input.dep_type == 1 { // MATERIALIZE = 1 - mermaid.push_str(&format!(" {} --> {}\n", ref_node_id, job_node_id)); + // Add the edge from input to job (avoid duplicates) + let edge_key = if input.dep_type == 1 { // MATERIALIZE = 1 + format!("{}-->{}", ref_node_id, job_node_id) } else { - // Dashed line for query dependencies - mermaid.push_str(&format!(" {} -.-> {}\n", ref_node_id, job_node_id)); + format!("{}-.->{}", ref_node_id, job_node_id) + }; + + if !added_edges.contains(&edge_key) { + if input.dep_type == 1 { // MATERIALIZE = 1 + mermaid.push_str(&format!(" {} --> {}\n", ref_node_id, job_node_id)); + } else { + // Dashed line for query dependencies + mermaid.push_str(&format!(" {} -.-> {}\n", ref_node_id, job_node_id)); + } + added_edges.insert(edge_key); } } } @@ -184,8 +194,12 @@ pub fn generate_mermaid_with_status( added_refs.insert(ref_node_id.clone()); } - // Add the edge from job to output - mermaid.push_str(&format!(" {} --> {}\n", job_node_id, ref_node_id)); + // Add the edge from job to output (avoid duplicates) + let edge_key = format!("{}-->{}", job_node_id, ref_node_id); + if !added_edges.contains(&edge_key) { + mermaid.push_str(&format!(" {} --> {}\n", job_node_id, ref_node_id)); + added_edges.insert(edge_key); + } } } }