Skip to content
Permalink
Browse files

don't rebuild in the middle of prepending siblings.

  • Loading branch information...
mceachen committed Jun 11, 2014
1 parent 96b4091 commit 31de226bc774ee37a9309fdcf84d6417cb5e87f6
Showing with 10 additions and 5 deletions.
  1. +1 −1 .rspec
  2. +6 −1 lib/closure_tree/hierarchy_maintenance.rb
  3. +3 −3 lib/closure_tree/numeric_deterministic_ordering.rb
2 .rspec
@@ -1 +1 @@
--format documentation --color
--format documentation --color --order random
@@ -15,6 +15,10 @@ def _ct_skip_cycle_detection!
@_ct_skip_cycle_detection = true
end

def _ct_skip_hierarchy_maintenance!
@_ct_skip_hierarchy_maintenance = true
end

def _ct_validate
if !@_ct_skip_cycle_detection &&
!new_record? && # don't validate for cycles if we're a new record
@@ -32,7 +36,7 @@ def _ct_before_save

def _ct_after_save
if changes[_ct.parent_column_name] || @was_new_record
rebuild!
rebuild! unless @_ct_skip_hierarchy_maintenance
end
if changes[_ct.parent_column_name] && !@was_new_record
# Resetting the ancestral collections addresses
@@ -41,6 +45,7 @@ def _ct_after_save
self_and_ancestors.reload
end
@was_new_record = false # we aren't new anymore.
@_ct_skip_hierarchy_maintenance = false # only skip once.
true # don't cancel anything.
end

@@ -85,9 +85,8 @@ def prepend_sibling(sibling_node)
def add_sibling(sibling, add_after = true)
fail "can't add self as sibling" if self == sibling

# Make sure self or sibling isn't dirty, because we're going to call reload:
# Make sure self isn't dirty, because we're going to call reload:
save
sibling.save

_ct.with_advisory_lock do
prior_sibling_parent = sibling.parent
@@ -97,8 +96,9 @@ def add_sibling(sibling, add_after = true)
self.order_value
end

sibling.update_order_value(self.order_value)
sibling.order_value = self.order_value
sibling.parent = self.parent
sibling._ct_skip_hierarchy_maintenance!
sibling.save # may be a no-op

_ct_reorder_siblings(reorder_from_value)

0 comments on commit 31de226

Please sign in to comment.
You can’t perform that action at this time.