Skip to content

Fix for adding children with << operator when order_is_numeric? #85

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 12, 2014
Merged

Fix for adding children with << operator when order_is_numeric? #85

merged 7 commits into from
Jun 12, 2014

Conversation

inetdavid
Copy link

Added tests for using << operator to add children when order_is_numeric? is true. (Proved bug)

Fix for Issue #84 where the order_value was left as nil when order_is_numeric? is true.

Fix for bad SQL statements when parent_id is nil (tree roots). Caused ordering problems for roots because root nodes wouldn't be matched by reorder_with_parent_id for PostgreSQL or MySQL.

David Schmidt added 6 commits January 16, 2014 14:48
First try to fix broken << operator.  Some tests still fail in sqlite, but fixes appear to work
when manually tested in PostgreSQL.  Checking in so I can clone on a CentOS box where PostgreSQL
tests can be run.
@inetdavid
Copy link
Author

NOTE: Travis tests for MySQL and PostgreSQL and Rails 4.1beta1 failed, but the failure was in the second execution after all tests had first passed. Failures appear to be in the code that creates the tables, not in implementation.

https://travis-ci.org/inetdavid/closure_tree

@mceachen
Copy link
Collaborator

Thanks for all this work!

I'll pull into a new branch and see if I can determine what's breaking.

@mceachen
Copy link
Collaborator

Hey there, so did you have a chance to look at append_sibling and prepend_sibling? I think they do what you want, very efficiently.

Do you think we should make add_child do the same as node.children.last.append_sibling?

I think if you're confused by the current API, that's proof that there's some work to be done here.

@@ -42,7 +42,7 @@ def find_or_create_at_same_time(name)
end
max_wait_time = @lock.synchronize { @wake_times.max }
sleep_time = max_wait_time - Time.now.to_f
$stderr.puts "sleeping for #{sleep_time}"
# $stderr.puts "sleeping for #{sleep_time}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I know it's janky, but I've fought with Travis enough with this issue to want to keep the stderr message in there.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries. It just looked real odd and made test output hard to read.

@inetdavid
Copy link
Author

As for your earlier question, I think the real issue was that nil was still allowed as a value for order_value, even if order_is_numeric? returns true. That certainly caused the << function to fail (and it's documented in the README as a valid way to add children). There could have been other side effects from those nil order_values. For instance, the .root method should pick the first of the available roots, but PostgreSQL in particular doesn't always return records ordered by ID by default (though MySQL seems to). This means you could get different root notes from the root method.

My fix assures that if order_by_numeric? is true then the order_value column is never saved with a nil value and minimizes the number of records that must be re-written when a new record is inserted since any record prior to the inserted record doesn't need to be re-written.

@mceachen mceachen merged commit 76f4423 into ClosureTree:master Jun 12, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants