closure_tree 3.6.7 → 3.6.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +5 -0
- data/lib/closure_tree/acts_as_tree.rb +17 -12
- data/lib/closure_tree/version.rb +1 -1
- metadata +3 -3
data/README.md
CHANGED
@@ -367,6 +367,11 @@ Closure tree is [tested under every combination](http://travis-ci.org/#!/mceache
|
|
367
367
|
|
368
368
|
## Change log
|
369
369
|
|
370
|
+
### 3.6.8
|
371
|
+
|
372
|
+
* [Don Morrison](https://github.com/elskwid) massaged the [#hash_tree](#nested-hashes) query to
|
373
|
+
be more efficient.
|
374
|
+
|
370
375
|
### 3.6.7
|
371
376
|
|
372
377
|
* Added workaround for ActiveRecord::Observer usage pre-db-creation. Addresses
|
@@ -93,21 +93,26 @@ module ClosureTree
|
|
93
93
|
tree = ActiveSupport::OrderedHash.new
|
94
94
|
id_to_hash = {}
|
95
95
|
limit_depth = (options[:limit_depth] || 10).to_i
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
96
|
+
|
97
|
+
# Simple join with hierarchy for ancestor, descendant, and generation
|
98
|
+
scope = joins(:ancestor_hierarchies)
|
99
|
+
|
100
|
+
# Deepest generation, within limit, for each descendant
|
101
|
+
scope = scope.joins(<<-SQL)
|
102
102
|
INNER JOIN (
|
103
|
-
SELECT
|
103
|
+
SELECT
|
104
|
+
#{quoted_hierarchy_table_name}.descendant_id,
|
105
|
+
MAX(#{quoted_hierarchy_table_name}.generations) AS depth
|
104
106
|
FROM #{quoted_hierarchy_table_name}
|
105
|
-
GROUP BY
|
106
|
-
HAVING MAX(generations) <= #{limit_depth - 1}
|
107
|
-
) AS
|
108
|
-
|
107
|
+
GROUP BY #{quoted_hierarchy_table_name}.descendant_id
|
108
|
+
HAVING MAX(#{quoted_hierarchy_table_name}.generations) <= #{limit_depth - 1}
|
109
|
+
) AS generation_depth
|
110
|
+
ON #{quoted_hierarchy_table_name}.descendant_id = generation_depth.descendant_id
|
109
111
|
SQL
|
110
|
-
|
112
|
+
|
113
|
+
scope = scope.order(append_order("generation_depth.depth"))
|
114
|
+
|
115
|
+
scope.each do |ea|
|
111
116
|
h = id_to_hash[ea.id] = ActiveSupport::OrderedHash.new
|
112
117
|
if ea.root?
|
113
118
|
tree[ea] = h
|
data/lib/closure_tree/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: closure_tree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.6.
|
4
|
+
version: 3.6.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -208,7 +208,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
208
208
|
version: '0'
|
209
209
|
segments:
|
210
210
|
- 0
|
211
|
-
hash:
|
211
|
+
hash: 1831255790364540871
|
212
212
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
213
213
|
none: false
|
214
214
|
requirements:
|
@@ -217,7 +217,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
217
217
|
version: '0'
|
218
218
|
segments:
|
219
219
|
- 0
|
220
|
-
hash:
|
220
|
+
hash: 1831255790364540871
|
221
221
|
requirements: []
|
222
222
|
rubyforge_project:
|
223
223
|
rubygems_version: 1.8.23
|