From a327ee8b318bff41d6196b283b18d29a06e1716a Mon Sep 17 00:00:00 2001 From: Nikolay Bekirov Date: Fri, 3 May 2019 18:01:52 +0300 Subject: [PATCH 1/2] Optimize the grouping behavior when finding by large path --- lib/closure_tree/support.rb | 2 +- spec/tag_examples.rb | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/closure_tree/support.rb b/lib/closure_tree/support.rb index 24459db9..734b68f5 100644 --- a/lib/closure_tree/support.rb +++ b/lib/closure_tree/support.rb @@ -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 diff --git a/spec/tag_examples.rb b/spec/tag_examples.rb index 14dd8cf7..ab716347 100644 --- a/spec/tag_examples.rb +++ b/spec/tag_examples.rb @@ -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 From f12748d7f5d29db865cc5d3806a7303147d0f7e6 Mon Sep 17 00:00:00 2001 From: Nikolay Bekirov Date: Tue, 7 May 2019 15:06:36 +0300 Subject: [PATCH 2/2] Update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c1dd592..be4dc6e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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