snapshot_tree 2.0.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/snapshot_tree/acts_as_tree.rb +3 -5
- data/lib/snapshot_tree/template.yml +28 -24
- data/lib/snapshot_tree/version.rb +1 -1
- data/lib/snapshot_tree.rb +1 -1
- data/snapshot_tree.gemspec +2 -2
- metadata +13 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05a07d646ae3dc57c2788ed5019c17cbd7dc66be
|
4
|
+
data.tar.gz: f1fdaebf5eb6d43815c2dbe8cb9de282422160cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d8a33504e55b3782ebc2b7cec8e408765128f7d499833c08d92c21345cfe4c1584a2335f502e99635f0404e8c9f1a35e0de6201dc834a9c78c4fbbd334c08cd
|
7
|
+
data.tar.gz: 51d08907178958e822716ebe4ffe5680ade9fa6cdadb82bf51a5faf4b174a1d1390ac7165a3a9fe52e685794ac76009cbab1cca434838705508173f4ec88c1f8
|
@@ -66,7 +66,7 @@ module SnapshotTree
|
|
66
66
|
dependent: options[:dependent]
|
67
67
|
|
68
68
|
has_many :child_tree_nodes,
|
69
|
-
-> { where(
|
69
|
+
-> { where(optoins[:is_active_field].to_sym => true) if options[:is_active_field] },
|
70
70
|
class_name: options[:join_class],
|
71
71
|
foreign_key: options[:parent_key],
|
72
72
|
autosave: true,
|
@@ -140,10 +140,8 @@ module SnapshotTree
|
|
140
140
|
def nodes_query(query_type)
|
141
141
|
return @query[query_type] if @query[query_type]
|
142
142
|
|
143
|
-
@query[query_type] =
|
144
|
-
@template["#{query_type}_query"]
|
145
|
-
).call(
|
146
|
-
{
|
143
|
+
@query[query_type] = Mustache.render(
|
144
|
+
@template["#{query_type}_query"], {
|
147
145
|
model_table: @opts[:model_table],
|
148
146
|
join_table: @opts[:join_table],
|
149
147
|
child_key: "#{@opts[:child_key]}",
|
@@ -1,36 +1,38 @@
|
|
1
1
|
root_query: |
|
2
2
|
(
|
3
3
|
SELECT model.* FROM {{model_table}} model
|
4
|
-
{{#
|
4
|
+
{{#snapshot_field}}
|
5
5
|
LEFT JOIN (
|
6
6
|
SELECT {{child_key}}, {{parent_key}}, {{snapshot_field}}, id,
|
7
|
-
{{#is_active_field}}{{
|
7
|
+
{{#is_active_field}}{{is_active_field}}, {{/is_active_field}}
|
8
8
|
RANK() OVER (PARTITION BY {{child_key}} ORDER BY {{snapshot_field}} DESC, id DESC)
|
9
9
|
FROM {{join_table}}
|
10
10
|
WHERE {{snapshot_field}} <= '__snapshot_value__'
|
11
|
-
{{#is_active_field}}AND {{
|
11
|
+
{{#is_active_field}}AND {{is_active_field}}{{/is_active_field}}
|
12
12
|
) AS tree ON tree.{{child_key}} = model.id AND COALESCE(tree.rank, 1) = 1
|
13
|
-
{{
|
13
|
+
{{/snapshot_field}}
|
14
|
+
{{^snapshot_field}}
|
14
15
|
LEFT JOIN {{join_table}} tree ON tree.{{child_key}} = model.id
|
15
|
-
{{/
|
16
|
+
{{/snapshot_field}}
|
16
17
|
WHERE tree.{{parent_key}} IS NULL
|
17
18
|
) AS {{model_table}}
|
18
19
|
|
19
20
|
leaf_query: |
|
20
21
|
(
|
21
22
|
SELECT model.* FROM {{model_table}} model
|
22
|
-
{{#
|
23
|
+
{{#snapshot_field}}
|
23
24
|
LEFT JOIN (
|
24
25
|
SELECT {{child_key}}, {{parent_key}}, {{snapshot_field}}, id,
|
25
|
-
{{#is_active_field}}{{
|
26
|
+
{{#is_active_field}}{{is_active_field}}, {{/is_active_field}}
|
26
27
|
RANK() OVER (PARTITION BY {{child_key}} ORDER BY {{snapshot_field}} DESC, id DESC)
|
27
28
|
FROM {{join_table}}
|
28
29
|
WHERE {{snapshot_field}} <= '__snapshot_value__'
|
29
|
-
{{#is_active_field}}AND {{
|
30
|
+
{{#is_active_field}}AND {{is_active_field}}{{/is_active_field}}
|
30
31
|
) AS tree ON tree.{{parent_key}} = model.id AND COALESCE(tree.rank, 1) = 1
|
31
|
-
{{
|
32
|
+
{{/snapshot_field}}
|
33
|
+
{{^snapshot_field}}
|
32
34
|
LEFT JOIN {{join_table}} tree ON tree.{{parent_key}} = model.id
|
33
|
-
{{/
|
35
|
+
{{/snapshot_field}}
|
34
36
|
WHERE tree.{{child_key}} IS NULL
|
35
37
|
) AS {{model_table}}
|
36
38
|
|
@@ -41,7 +43,7 @@ descendent_query: |
|
|
41
43
|
alias.{{child_key}}, alias.{{parent_key}},
|
42
44
|
ARRAY[alias.{{parent_key}}] AS {{path}}, 1 AS {{depth}}, false AS {{cycle}}
|
43
45
|
FROM {{join_table}} alias
|
44
|
-
{{#
|
46
|
+
{{#snapshot_field}}JOIN snapshot ON snapshot.id = alias.id{{/snapshot_field}}
|
45
47
|
WHERE alias.{{parent_key}} = __model_id__
|
46
48
|
UNION ALL
|
47
49
|
SELECT
|
@@ -51,24 +53,25 @@ descendent_query: |
|
|
51
53
|
alias.{{child_key}} = ANY(tree.{{path}}) AS {{cycle}}
|
52
54
|
FROM tree
|
53
55
|
JOIN {{join_table}} alias ON alias.{{parent_key}} = tree.{{child_key}}
|
54
|
-
{{#
|
56
|
+
{{#snapshot_field}}JOIN snapshot ON snapshot.id = alias.id{{/snapshot_field}}
|
55
57
|
WHERE NOT tree.{{cycle}}
|
56
58
|
)
|
57
59
|
,snapshot AS (
|
58
60
|
SELECT alias.id
|
59
61
|
FROM {{model_table}} model
|
60
|
-
{{#
|
62
|
+
{{#snapshot_field}}
|
61
63
|
LEFT JOIN (
|
62
64
|
SELECT {{child_key}}, {{parent_key}}, {{snapshot_field}}, id,
|
63
|
-
{{#is_active_field}}{{
|
65
|
+
{{#is_active_field}}{{is_active_field}}, {{/is_active_field}}
|
64
66
|
RANK() OVER (PARTITION BY {{child_key}} ORDER BY {{snapshot_field}} DESC, id DESC)
|
65
67
|
FROM {{join_table}}
|
66
68
|
WHERE {{snapshot_field}} <= '__snapshot_value__'
|
67
|
-
{{#is_active_field}}AND {{
|
69
|
+
{{#is_active_field}}AND {{is_active_field}}{{/is_active_field}}
|
68
70
|
) AS alias ON alias.{{child_key}} = model.id AND COALESCE(rank, 1) = 1
|
69
|
-
{{
|
71
|
+
{{/snapshot_field}}
|
72
|
+
{{^snapshot_field}}
|
70
73
|
LEFT JOIN {{join_table}} alias ON alias.{{child_key}} = model.id
|
71
|
-
{{/
|
74
|
+
{{/snapshot_field}}
|
72
75
|
WHERE alias.{{parent_key}} IS NOT NULL
|
73
76
|
)
|
74
77
|
SELECT model.*, tree.*
|
@@ -84,7 +87,7 @@ ancestor_query: |
|
|
84
87
|
alias.{{child_key}}, alias.{{parent_key}},
|
85
88
|
ARRAY[alias.{{parent_key}}] AS {{path}}, 1 AS {{depth}}, false AS {{cycle}}
|
86
89
|
FROM {{join_table}} alias
|
87
|
-
{{#
|
90
|
+
{{#snapshot_field}}JOIN snapshot ON snapshot.id = alias.id{{/snapshot_field}}
|
88
91
|
WHERE alias.{{child_key}} = __model_id__
|
89
92
|
UNION ALL
|
90
93
|
SELECT
|
@@ -94,24 +97,25 @@ ancestor_query: |
|
|
94
97
|
alias.{{parent_key}} = ANY(tree.{{path}}) AS {{cycle}}
|
95
98
|
FROM tree
|
96
99
|
JOIN {{join_table}} alias ON alias.{{child_key}} = tree.{{parent_key}}
|
97
|
-
{{#
|
100
|
+
{{#snapshot_field}}JOIN snapshot ON snapshot.id = alias.id{{/snapshot_field}}
|
98
101
|
WHERE NOT tree.{{cycle}}
|
99
102
|
)
|
100
103
|
,snapshot AS (
|
101
104
|
SELECT alias.id
|
102
105
|
FROM {{model_table}} model
|
103
|
-
{{#
|
106
|
+
{{#snapshot_field}}
|
104
107
|
LEFT JOIN (
|
105
108
|
SELECT {{child_key}}, {{parent_key}}, {{snapshot_field}}, id,
|
106
|
-
{{#is_active_field}}{{
|
109
|
+
{{#is_active_field}}{{is_active_field}}, {{/is_active_field}}
|
107
110
|
RANK() OVER (PARTITION BY {{child_key}} ORDER BY {{snapshot_field}} DESC, id DESC)
|
108
111
|
FROM {{join_table}}
|
109
112
|
WHERE {{snapshot_field}} <= '__snapshot_value__'
|
110
|
-
{{#is_active_field}}AND {{
|
113
|
+
{{#is_active_field}}AND {{is_active_field}}{{/is_active_field}}
|
111
114
|
) AS alias ON alias.{{child_key}} = model.id AND COALESCE(rank, 1) = 1
|
112
|
-
{{
|
115
|
+
{{/snapshot_field}}
|
116
|
+
{{^snapshot_field}}
|
113
117
|
LEFT JOIN {{join_table}} alias ON alias.{{child_key}} = model.id
|
114
|
-
{{/
|
118
|
+
{{/snapshot_field}}
|
115
119
|
WHERE alias.{{parent_key}} IS NOT NULL
|
116
120
|
)
|
117
121
|
SELECT model.*, tree.*
|
data/lib/snapshot_tree.rb
CHANGED
data/snapshot_tree.gemspec
CHANGED
@@ -4,7 +4,7 @@ require File.expand_path('../lib/snapshot_tree/version', __FILE__)
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
5
|
gem.authors = ["Szetobo"]
|
6
6
|
gem.email = ["szetobo@gmail.com"]
|
7
|
-
gem.homepage = "https://github.com/
|
7
|
+
gem.homepage = "https://github.com/ABAgile/snapshot_tree"
|
8
8
|
gem.summary = "Mutliple snapshot hierarchical tree implementation of adjacency list using recursive query of Postgresql"
|
9
9
|
gem.description = "Mutliple snapshot hierarchical tree implementation of adjacency list using recursive query of Postgresql"
|
10
10
|
|
@@ -18,7 +18,7 @@ Gem::Specification.new do |gem|
|
|
18
18
|
gem.add_dependency "activerecord", ">= 4.0.0"
|
19
19
|
gem.add_dependency "activesupport", ">= 4.0.0"
|
20
20
|
gem.add_dependency "pg", ">= 0.17.1"
|
21
|
-
gem.add_dependency "
|
21
|
+
gem.add_dependency "mustache", "~> 1.0"
|
22
22
|
|
23
23
|
gem.add_development_dependency "rake"
|
24
24
|
gem.add_development_dependency "rspec", "~> 2.14"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: snapshot_tree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Szetobo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -53,19 +53,19 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 0.17.1
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: mustache
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: '1.0'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: '1.0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rake
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -146,7 +146,7 @@ files:
|
|
146
146
|
- spec/db/schema.rb
|
147
147
|
- spec/setup.rb
|
148
148
|
- spec/spec_helper.rb
|
149
|
-
homepage: https://github.com/
|
149
|
+
homepage: https://github.com/ABAgile/snapshot_tree
|
150
150
|
licenses: []
|
151
151
|
metadata: {}
|
152
152
|
post_install_message:
|
@@ -165,9 +165,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
165
165
|
version: '0'
|
166
166
|
requirements: []
|
167
167
|
rubyforge_project:
|
168
|
-
rubygems_version: 2.
|
168
|
+
rubygems_version: 2.6.14.3
|
169
169
|
signing_key:
|
170
170
|
specification_version: 4
|
171
171
|
summary: Mutliple snapshot hierarchical tree implementation of adjacency list using
|
172
172
|
recursive query of Postgresql
|
173
|
-
test_files:
|
173
|
+
test_files:
|
174
|
+
- spec/acts_as_tree_spec.rb
|
175
|
+
- spec/db/database.yml.sample
|
176
|
+
- spec/db/schema.rb
|
177
|
+
- spec/setup.rb
|
178
|
+
- spec/spec_helper.rb
|