Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

### 7.1.0

- Optimize the grouping behavior when finding by large path [PR 347](https://github.com/ClosureTree/closure_tree/pull/347)

### 7.0.0
Closure Tree is now tested against Rails 5.2

Expand Down
2 changes: 1 addition & 1 deletion lib/closure_tree/support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def max_join_tables
def find_by_large_path(path, attributes = {}, parent_id = nil)
next_parent_id = parent_id
child = nil
path.in_groups(max_join_tables, false).each do |subpath|
path.in_groups_of(max_join_tables, false).each do |subpath|
child = model_class.find_by_path(subpath, attributes, next_parent_id)
return nil if child.nil?
next_parent_id = child._ct_id
Expand Down
8 changes: 5 additions & 3 deletions spec/tag_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -781,11 +781,13 @@ def assert_parent_and_children
end

it 'finds_by_path for very deep trees' do
expect(tag_class._ct).to receive(:max_join_tables).at_least(1).and_return(3)
path = (1..20).to_a.map { |ea| ea.to_s }
expect(tag_class._ct).to receive(:max_join_tables).at_least(1).and_return(20)
path = (1..70).to_a.map { |ea| ea.to_s }
subject = tag_class.find_or_create_by_path(path)
expect(subject.ancestry_path).to eq(path)
expect(tag_class.find_by_path(path)).to eq(subject)
expect(count_queries do
expect(tag_class.find_by_path(path)).to eq(subject)
end).to eq(4)
root = subject.root
expect(root.find_by_path(path[1..-1])).to eq(subject)
end
Expand Down