<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<TITLE>Message</TITLE>
<META content="MSHTML 6.00.6000.16481" name=GENERATOR></HEAD>
<BODY text=#000000 bgColor=#ffffff>
<DIV><SPAN class=921244710-15082007><FONT face=Arial size=2>Now you've got me
worried! </FONT></SPAN></DIV>
<DIV><SPAN class=921244710-15082007><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=921244710-15082007><FONT face=Arial size=2>I'm currently using
tags/stable and although I've had no problems with it, looking through the
repository it looks like trunk has moved on significantly. Is trunk fully
backwards compatible?</FONT></SPAN></DIV>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<DIV></DIV>
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left><FONT
face=Tahoma size=2>-----Original Message-----<BR><B>From:</B>
betternestedset-talk-bounces@rubyforge.org
[mailto:betternestedset-talk-bounces@rubyforge.org] <B>On Behalf Of </B>Jeremy
Nicoll<BR><B>Sent:</B> 14 August 2007 21:12<BR><B>To:</B>
betternestedset-talk@rubyforge.org<BR><B>Subject:</B> Re:
[Betternestedset-talk] Concurrency
issues?<BR><BR></FONT></DIV> Thanks Matt - I'm glad you
found this before my app went to production :). Good luck with
yours.<BR><BR>--<BR>Jeremy Nicoll<BR><BR>Krishna Dole wrote:
<BLOCKQUOTE
cite=mid:8d64b97d0708141257o4bc6d348j8241255885ef32c0@mail.gmail.com
type="cite"><PRE wrap="">Hey Matt,
You were right-- there was a bug in the renumbering when working with
virtual roots. I have fixed it in trunk. You can get the fixed version
with
script/plugin install svn://rubyforge.org/var/svn/betternestedset/trunk
Thanks for reporting this.
Krishna
On 8/14/07, Matt Rogish <A class=moz-txt-link-rfc2396E href="mailto:rogishmn@muohio.edu"><rogishmn@muohio.edu></A> wrote:
</PRE>
<BLOCKQUOTE type="cite"><PRE wrap="">My guess is that there's a bug in the implementation of
renumber_full_tree/calc_numbers which is causing this problem. The dataset
with overlapping numbers is what resulted from applying renumber_full_tree;
thus something is not quite right with that method...
I have a copy of SQL for Smarties (2nd ed), so I'll try and see if the two
algorithms diverge at all and/or provide a patch if I can help it. :)
Thanks,
--
Matt
On 8/14/07, Matt Rogish <A class=moz-txt-link-rfc2396E href="mailto:matt.rogish@gmail.com"><matt.rogish@gmail.com></A> wrote:
</PRE>
<BLOCKQUOTE type="cite"><PRE wrap="">The problem is, as I see it, overlapping left and right columns. Shouldn't
</PRE></BLOCKQUOTE><PRE wrap="">the lft/right be one apart, or am I wrong.
</PRE>
<BLOCKQUOTE type="cite"><PRE wrap="">For example:
mysql> select id, parent_id, lft, rgt from messages where message_board_id
</PRE></BLOCKQUOTE><PRE wrap="">= 1926 and parent_id is null order by lft;
</PRE>
<BLOCKQUOTE type="cite"><PRE wrap="">+--------+-----------+------+------+
| id | parent_id | lft | rgt |
+--------+-----------+------+------+
| 9472 | NULL | 1 | 2 |
| 9473 | NULL | 2 | 37 |
| 9474 | NULL | 37 | 44 |
| 9475 | NULL | 44 | 45 |
| 9476 | NULL | 45 | 74 |
| 9477 | NULL | 74 | 75 |
| 9478 | NULL | 75 | 114 |
| 9487 | NULL | 114 | 179 |
| 9479 | NULL | 179 | 348 |
| 9488 | NULL | 478 | 515 |
| 9482 | NULL | 515 | 520 |
| 9483 | NULL | 520 | 525 |
| 9484 | NULL | 525 | 526 |
| 9485 | NULL | 526 | 579 |
| 334881 | NULL | 579 | 580 |
| 335201 | NULL | 581 | 584 |
| 335234 | NULL | 585 | 586 |
+--------+-----------+------+------+
So the only ones "correct" are id = 335201 and id = 335234?
I attached the entire dataset. What is happening is that the BETWEEN
</PRE></BLOCKQUOTE><PRE wrap="">statement that better nested set is executing looks something like this:
</PRE>
<BLOCKQUOTE type="cite"><PRE wrap="">m = Message.find( 9478 )
m.all_children.each{ stuff }
SQL is:
SELECT * FROM messages WHERE (message_board_id = 1926 AND (lft BETWEEN 75
</PRE></BLOCKQUOTE><PRE wrap="">AND 114)) ORDER BY lf
</PRE>
<BLOCKQUOTE type="cite"><PRE wrap="">Since BETWEEN is inclusive, that result pulls all the children correctly
</PRE></BLOCKQUOTE><PRE wrap="">but incorrectly pulls out the next root, message id = 9487.
</PRE>
<BLOCKQUOTE type="cite"><PRE wrap="">I'm not sure if that means renumber_entire_tree needs to be fixed, or the
</PRE></BLOCKQUOTE><PRE wrap="">actual move_to_child does, but something isn't right.
</PRE>
<BLOCKQUOTE type="cite"><PRE wrap="">--
Matt
On 8/14/07, Matt Rogish <A class=moz-txt-link-rfc2396E href="mailto:rogishmn@muohio.edu"><rogishmn@muohio.edu></A> wrote:
</PRE>
<BLOCKQUOTE type="cite"><PRE wrap="">I'm not writing any SQL, I'm using built-in better-nested-set functions.
Here's my save:
def create
@message = Message.new(params[:message])
if @message.save
flash[:notice] = 'Message was successfully created.'
if params[:message][:parent_id]
@message.move_to_child_of( Message.find
</PRE></BLOCKQUOTE></BLOCKQUOTE><PRE wrap="">params[:message][:parent_id] )
</PRE>
<BLOCKQUOTE type="cite">
<BLOCKQUOTE type="cite"><PRE wrap=""> @message.save
end
end
end
--
Matt
On 8/14/07, Jeremy Nicoll <A class=moz-txt-link-rfc2396E href="mailto:jnicoll@goldnoteexpress.com"><jnicoll@goldnoteexpress.com ></A> wrote:
</PRE>
<BLOCKQUOTE type="cite"><PRE wrap=""> I think it would be best if you could post your SQL that is messed
</PRE></BLOCKQUOTE></BLOCKQUOTE></BLOCKQUOTE><PRE wrap="">up as well as the code you are using to save your nodes. Unfortunately we
can't tell you what is wrong until we actually see the logic behind what you
are doing.
</PRE>
<BLOCKQUOTE type="cite">
<BLOCKQUOTE type="cite">
<BLOCKQUOTE type="cite"><PRE wrap="">--
Jeremy Nicoll
Matt Rogish wrote:
How can I repair my tree?
I have a message board system in which the messages are grouped by
</PRE></BLOCKQUOTE></BLOCKQUOTE></BLOCKQUOTE><PRE wrap="">"message_board_id", thus my model is:
</PRE>
<BLOCKQUOTE type="cite">
<BLOCKQUOTE type="cite">
<BLOCKQUOTE type="cite"><PRE wrap="">acts_as_nested_set :scope => :message_board_id
Somehow the tree is messed up, inasmuch as some roots (parent_id ==
</PRE></BLOCKQUOTE></BLOCKQUOTE></BLOCKQUOTE><PRE wrap="">null) are being set to the children of some other message, so I cannot
successfully repair it. I'm not sure if I'm performing incorrect operations
or what, but somehow I need to repair my tree where message_board_id = 34
(or whatever it is).
</PRE>
<BLOCKQUOTE type="cite">
<BLOCKQUOTE type="cite">
<BLOCKQUOTE type="cite"><PRE wrap="">It seems as if renumber_full_tree tries to find the virtual root for a
</PRE></BLOCKQUOTE></BLOCKQUOTE></BLOCKQUOTE><PRE wrap="">given node, but since the root itself is a CHILD of another node, the whole
thing fails. My layman's guess is that the "root" condition is wrong, since
it's doing WHERE parent_id IS NULL ... AND lft BETWEEN .. AND ..
</PRE>
<BLOCKQUOTE type="cite">
<BLOCKQUOTE type="cite">
<BLOCKQUOTE type="cite"><PRE wrap="">Well, if the root is incorrectly between something, then the lft would
</PRE></BLOCKQUOTE></BLOCKQUOTE></BLOCKQUOTE><PRE wrap="">fail, no? Maybe I'm misreading that. Help!!
</PRE>
<BLOCKQUOTE type="cite">
<BLOCKQUOTE type="cite">
<BLOCKQUOTE type="cite"><PRE wrap="">Thanks,
--
Matt
On 8/14/07, Matt Rogish <A class=moz-txt-link-rfc2396E href="mailto:rogishmn@muohio.edu"><rogishmn@muohio.edu></A> wrote:
</PRE>
<BLOCKQUOTE type="cite"><PRE wrap="">Under heavy load we are getting significantly screwed up data. I
</PRE></BLOCKQUOTE></BLOCKQUOTE></BLOCKQUOTE></BLOCKQUOTE><PRE wrap="">have to run renumber_full_tree in script/console production order to repair
the thing.
</PRE>
<BLOCKQUOTE type="cite">
<BLOCKQUOTE type="cite">
<BLOCKQUOTE type="cite">
<BLOCKQUOTE type="cite"><PRE wrap="">Obviously this is a bad thing, but I don't even know where to start
</PRE></BLOCKQUOTE></BLOCKQUOTE></BLOCKQUOTE></BLOCKQUOTE><PRE wrap="">to fix it. Any ideas?
</PRE>
<BLOCKQUOTE type="cite">
<BLOCKQUOTE type="cite">
<BLOCKQUOTE type="cite">
<BLOCKQUOTE type="cite"><PRE wrap="">Thanks,
--
Matt
</PRE></BLOCKQUOTE><PRE wrap="">________________________________
</PRE></BLOCKQUOTE></BLOCKQUOTE></BLOCKQUOTE>
<BLOCKQUOTE type="cite">
<BLOCKQUOTE type="cite">
<BLOCKQUOTE type="cite"><PRE wrap="">_______________________________________________
Betternestedset-talk mailing list
<A class=moz-txt-link-abbreviated href="mailto:Betternestedset-talk@rubyforge.org">Betternestedset-talk@rubyforge.org</A>
</PRE></BLOCKQUOTE></BLOCKQUOTE></BLOCKQUOTE><PRE wrap=""><A class=moz-txt-link-freetext href="http://rubyforge.org/mailman/listinfo/betternestedset-talk">http://rubyforge.org/mailman/listinfo/betternestedset-talk</A>
</PRE>
<BLOCKQUOTE type="cite">
<BLOCKQUOTE type="cite">
<BLOCKQUOTE type="cite"><PRE wrap="">_______________________________________________
Betternestedset-talk mailing list
<A class=moz-txt-link-abbreviated href="mailto:Betternestedset-talk@rubyforge.org">Betternestedset-talk@rubyforge.org</A>
</PRE></BLOCKQUOTE></BLOCKQUOTE></BLOCKQUOTE><PRE wrap=""><A class=moz-txt-link-freetext href="http://rubyforge.org/mailman/listinfo/betternestedset-talk">http://rubyforge.org/mailman/listinfo/betternestedset-talk</A>
</PRE>
<BLOCKQUOTE type="cite">
<BLOCKQUOTE type="cite">
<BLOCKQUOTE type="cite"><PRE wrap=""> </PRE></BLOCKQUOTE><PRE wrap=""> </PRE></BLOCKQUOTE><PRE wrap="">
</PRE></BLOCKQUOTE><PRE wrap="">_______________________________________________
Betternestedset-talk mailing list
<A class=moz-txt-link-abbreviated href="mailto:Betternestedset-talk@rubyforge.org">Betternestedset-talk@rubyforge.org</A>
<A class=moz-txt-link-freetext href="http://rubyforge.org/mailman/listinfo/betternestedset-talk">http://rubyforge.org/mailman/listinfo/betternestedset-talk</A>
</PRE></BLOCKQUOTE><PRE wrap=""><!---->_______________________________________________
Betternestedset-talk mailing list
<A class=moz-txt-link-abbreviated href="mailto:Betternestedset-talk@rubyforge.org">Betternestedset-talk@rubyforge.org</A>
<A class=moz-txt-link-freetext href="http://rubyforge.org/mailman/listinfo/betternestedset-talk">http://rubyforge.org/mailman/listinfo/betternestedset-talk</A>
</PRE></BLOCKQUOTE></BLOCKQUOTE></BODY></HTML>