From f2b5efc556c97048bc13469d62d2b7375cd4ad91 Mon Sep 17 00:00:00 2001 From: Zachary Hamm Date: Fri, 20 Dec 2024 14:29:42 -0600 Subject: [PATCH] fix: view deletion if components are deleted If components are deleted, then the view deleted, the geometry for the component might be there in the graph still. It will be removed on view deletion. Be graceful here, and allow the view to be deleted in this case. --- .../node_weight/view_node_weight/v1.rs | 48 ++++++++++--------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/lib/dal/src/workspace_snapshot/node_weight/view_node_weight/v1.rs b/lib/dal/src/workspace_snapshot/node_weight/view_node_weight/v1.rs index 3e2b7189ce..3e81eb46d0 100644 --- a/lib/dal/src/workspace_snapshot/node_weight/view_node_weight/v1.rs +++ b/lib/dal/src/workspace_snapshot/node_weight/view_node_weight/v1.rs @@ -122,37 +122,39 @@ impl CorrectTransforms for ViewNodeWeightV1 { // We want the one most likely to have the smaller cardinality to be the one we // loop over in the inner loop to try to minimize the number of iterations. if !removed_geometries.contains(&existing_geometry_id.into()) { - let represented_thing_idx = workspace_snapshot_graph - .get_edge_weight_kind_target_idx( + if let Ok(Some(represented_thing_idx)) = workspace_snapshot_graph + .get_edge_weight_kind_target_idx_opt( destination, Direction::Outgoing, EdgeWeightKindDiscriminants::Represents, - )?; - if let NodeWeight::Component(component) = - workspace_snapshot_graph.get_node_weight(represented_thing_idx)? + ) { - if removed_components.contains(&component.id().into()) { - // If both the View and the Components represented in the View are being - // removed, then there won't be individual Update::RemoveEdge for the - // Geometry, so we need to check if the Component itself is being removed. - continue; + if let NodeWeight::Component(component) = + workspace_snapshot_graph.get_node_weight(represented_thing_idx)? + { + if removed_components.contains(&component.id().into()) { + // If both the View and the Components represented in the View are being + // removed, then there won't be individual Update::RemoveEdge for the + // Geometry, so we need to check if the Component itself is being removed. + continue; + } + + // If the Component isn't being removed, we need to make sure that it still + // exists in at least one other View to make sure we're not orphaning it. + let mut appears_in_views = workspace_snapshot_graph + .component_contained_in_views(component.id().into())?; + let my_id: ViewId = self.id().into(); + appears_in_views.retain(|&view_id| my_id != view_id); + + if !appears_in_views.is_empty() { + continue; + } } - // If the Component isn't being removed, we need to make sure that it still - // exists in at least one other View to make sure we're not orphaning it. - let mut appears_in_views = workspace_snapshot_graph - .component_contained_in_views(component.id().into())?; - let my_id: ViewId = self.id().into(); - appears_in_views.retain(|&view_id| my_id != view_id); + updates.remove(view_removal_update_idx); - if !appears_in_views.is_empty() { - continue; - } + return Ok(updates); } - - updates.remove(view_removal_update_idx); - - return Ok(updates); } } }