[Betternestedset-talk] Questions, RC for 0.1?

Krishna Dole
2006-12-13T01:03:51Z

Hi JCM et al.,

I''ve been committing a bunch of changes over the last few days, and
we''re down to one ticket on trac now, so I think we should start
considering the current code as a release candidate for 0.1.

I''ve come across some things I wanted to ask about, though.

First of all, I think that #move_to_child_of should insert the new
child to the right of existing children. Here''s why:
- consistent with the creation of new records (to the right of existing ones)
- consistent with #add_child
- consistent with default ordering for things like threaded posts,
where new items are added after existing ones
- if the parent has a large number of children relative to the size of
the tree, performance will be better, because fewer rows need to be
updated

What do you think? I know this will be a compatibility issue, so if we
are going to do it  perhaps we should wait until after 0.1.

The second thing I want to talk about would also cause compatibility
problems. ;)  It concerns #children_count. The present name of the
method is highly misleading, because it actually counts _all_ children
of the node, so presently node.children.size != node.children_count.
If we are going to change it to #all_children_count, I would favor
changing it to the much more natural #count_all_children instead. (I
would also change #leaves_count to #count_leaves). Thoughts?

The third issue concerns concurrency problems. Prior to revision 25,
the following code would corrupt the left/right indexes:

    c1, c2, c3 = Category.create, Category.create, Category.create
    c1.move_to_right_of(c3)
    c2.save  # c2 is stale, and overwrites the correct lft/rgt values

My solution was to override the #update method in ActiveRecord to
ignore the lft/rgt columns (the code is at the bottom of
better_nested_set.rb). I don''t know if this is a good way to do
things, so I''m hoping that someone else can take a look at the code
and see if it is sane.


Cheers,
Krishna