forest_liana 3.0.0.pre.beta.6 → 3.0.0.pre.beta.7
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.
- checksums.yaml +4 -4
- data/app/services/forest_liana/base_getter.rb +9 -1
- data/app/services/forest_liana/has_many_getter.rb +16 -15
- data/app/services/forest_liana/leaderboard_stat_getter.rb +6 -5
- data/app/services/forest_liana/line_stat_getter.rb +1 -1
- data/app/services/forest_liana/pie_stat_getter.rb +2 -2
- data/app/services/forest_liana/resource_getter.rb +2 -8
- data/app/services/forest_liana/resources_getter.rb +20 -10
- data/app/services/forest_liana/search_query_builder.rb +16 -5
- data/app/services/forest_liana/stat_getter.rb +1 -8
- data/app/services/forest_liana/value_stat_getter.rb +2 -2
- data/lib/forest_liana/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc42f7cf5b68fc7d00df278839bb4d43f78a2356
|
4
|
+
data.tar.gz: c16e1f5d465917736a6c271be80a901c02430957
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a15a4d4944f550e2f485b77dc4d4ecb48ded22042bf0523f01a0fc4e7977cc1aee7590647f804fc5a25bbae2163c3f198ac2fdc7665445de46ed0498cb213860
|
7
|
+
data.tar.gz: 3386847ab59536d942d296d775265f0f95e73e95943e16e3836f5152d9f3f0dc4ef810a9dbc7b900b43bb38bba137c14effdcedbf6789077804ffa7cbcaa8d54
|
@@ -14,7 +14,7 @@ module ForestLiana
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def includes_for_serialization
|
17
|
-
includes_initial = includes
|
17
|
+
includes_initial = @includes
|
18
18
|
includes_for_smart_belongs_to = @collection.fields_smart_belongs_to.map { |field| field[:field] }
|
19
19
|
|
20
20
|
if @field_names_requested
|
@@ -23,5 +23,13 @@ module ForestLiana
|
|
23
23
|
|
24
24
|
includes_initial.concat(includes_for_smart_belongs_to).map(&:to_s)
|
25
25
|
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def compute_includes
|
30
|
+
@includes = SchemaUtils.one_associations(@resource)
|
31
|
+
.select { |association| SchemaUtils.model_included?(association.klass) }
|
32
|
+
.map(&:name)
|
33
|
+
end
|
26
34
|
end
|
27
35
|
end
|
@@ -10,8 +10,9 @@ module ForestLiana
|
|
10
10
|
@collection_name = ForestLiana.name_for(model_association)
|
11
11
|
@field_names_requested = field_names_requested
|
12
12
|
@collection = get_collection(@collection_name)
|
13
|
-
|
14
|
-
|
13
|
+
compute_includes()
|
14
|
+
includes_symbols = @includes.map { |include| include.to_sym }
|
15
|
+
@search_query_builder = SearchQueryBuilder.new(@params, includes_symbols, {}, @collection)
|
15
16
|
|
16
17
|
prepare_query()
|
17
18
|
end
|
@@ -29,8 +30,18 @@ module ForestLiana
|
|
29
30
|
@search_query_builder.perform(@records)
|
30
31
|
end
|
31
32
|
|
32
|
-
def
|
33
|
-
@
|
33
|
+
def query_for_batch
|
34
|
+
@records
|
35
|
+
end
|
36
|
+
|
37
|
+
def records
|
38
|
+
@records.limit(limit).offset(offset)
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def compute_includes
|
44
|
+
@includes = @association.klass
|
34
45
|
.reflect_on_all_associations
|
35
46
|
.select do |association|
|
36
47
|
inclusion = !association.options[:polymorphic] &&
|
@@ -46,16 +57,6 @@ module ForestLiana
|
|
46
57
|
.map { |association| association.name.to_s }
|
47
58
|
end
|
48
59
|
|
49
|
-
def query_for_batch
|
50
|
-
@records
|
51
|
-
end
|
52
|
-
|
53
|
-
def records
|
54
|
-
@records.limit(limit).offset(offset)
|
55
|
-
end
|
56
|
-
|
57
|
-
private
|
58
|
-
|
59
60
|
def field_names_requested
|
60
61
|
return nil unless @params[:fields] && @params[:fields][@collection_name]
|
61
62
|
@params[:fields][@collection_name].split(',')
|
@@ -74,7 +75,7 @@ module ForestLiana
|
|
74
75
|
@records = get_resource()
|
75
76
|
.find(@params[:id])
|
76
77
|
.send(@params[:association_name])
|
77
|
-
.eager_load(includes)
|
78
|
+
.eager_load(@includes)
|
78
79
|
end
|
79
80
|
|
80
81
|
def offset
|
@@ -1,9 +1,10 @@
|
|
1
1
|
module ForestLiana
|
2
2
|
class LeaderboardStatGetter < StatGetter
|
3
3
|
def initialize(resource, params)
|
4
|
-
|
5
|
-
|
4
|
+
@resource = resource
|
5
|
+
@params = params
|
6
6
|
@model_relationship = @resource.reflect_on_association(@params[:relationship_field]).klass
|
7
|
+
compute_includes()
|
7
8
|
@label_field = @params[:label_field]
|
8
9
|
@aggregate = @params[:aggregate].downcase
|
9
10
|
@aggregate_field = @params[:aggregate_field]
|
@@ -13,7 +14,7 @@ module ForestLiana
|
|
13
14
|
|
14
15
|
def perform
|
15
16
|
result = @model_relationship
|
16
|
-
.joins(includes)
|
17
|
+
.joins(@includes)
|
17
18
|
.group(@groub_by)
|
18
19
|
.order(order)
|
19
20
|
.limit(@limit)
|
@@ -23,8 +24,8 @@ module ForestLiana
|
|
23
24
|
@record = Model::Stat.new(value: result)
|
24
25
|
end
|
25
26
|
|
26
|
-
def
|
27
|
-
SchemaUtils.one_associations(@model_relationship)
|
27
|
+
def compute_includes
|
28
|
+
@includes = SchemaUtils.one_associations(@model_relationship)
|
28
29
|
.select { |association| SchemaUtils.model_included?(association.klass) }
|
29
30
|
.map(&:name)
|
30
31
|
end
|
@@ -19,7 +19,7 @@ module ForestLiana
|
|
19
19
|
end
|
20
20
|
|
21
21
|
result = get_resource()
|
22
|
-
.eager_load(includes)
|
22
|
+
.eager_load(@includes)
|
23
23
|
.where(conditions.join(filter_operator))
|
24
24
|
.group(group_by_field)
|
25
25
|
.order(order)
|
@@ -62,7 +62,7 @@ module ForestLiana
|
|
62
62
|
if @params[:aggregate].downcase == 'sum'
|
63
63
|
field = @params[:aggregate_field].downcase
|
64
64
|
else
|
65
|
-
field = Rails::VERSION::MAJOR >= 5 || includes.size > 0 ? 'id' : 'all'
|
65
|
+
field = Rails::VERSION::MAJOR >= 5 || @includes.size > 0 ? 'id' : 'all'
|
66
66
|
end
|
67
67
|
"#{@params[:aggregate].downcase}_#{field} #{order}"
|
68
68
|
end
|
@@ -7,17 +7,11 @@ module ForestLiana
|
|
7
7
|
@params = params
|
8
8
|
@collection_name = ForestLiana.name_for(@resource)
|
9
9
|
@collection = get_collection(@collection_name)
|
10
|
+
compute_includes()
|
10
11
|
end
|
11
12
|
|
12
13
|
def perform
|
13
|
-
@record = get_resource().eager_load(includes).find(@params[:id])
|
14
|
+
@record = get_resource().eager_load(@includes).find(@params[:id])
|
14
15
|
end
|
15
|
-
|
16
|
-
def includes
|
17
|
-
SchemaUtils.one_associations(@resource)
|
18
|
-
.select { |association| SchemaUtils.model_included?(association.klass) }
|
19
|
-
.map(&:name)
|
20
|
-
end
|
21
|
-
|
22
16
|
end
|
23
17
|
end
|
@@ -10,21 +10,23 @@ module ForestLiana
|
|
10
10
|
@collection_name = ForestLiana.name_for(@resource)
|
11
11
|
@collection = get_collection(@collection_name)
|
12
12
|
@field_names_requested = field_names_requested
|
13
|
+
@tables_associated_to_relations_name = {}
|
13
14
|
get_segment()
|
14
|
-
|
15
|
+
compute_includes()
|
16
|
+
@search_query_builder = SearchQueryBuilder.new(@params, @includes, @tables_associated_to_relations_name, @collection)
|
15
17
|
|
16
18
|
prepare_query()
|
17
19
|
end
|
18
20
|
|
19
21
|
def perform
|
20
|
-
@records = @records.eager_load(includes)
|
22
|
+
@records = @records.eager_load(@includes)
|
21
23
|
@records_sorted = sort_query
|
22
24
|
end
|
23
25
|
|
24
26
|
def count
|
25
|
-
# NOTICE: For performance reasons, do not eager load the data if there is
|
26
|
-
#
|
27
|
-
@records_count = @count_needs_includes ? @records.eager_load(includes).count : @records.count
|
27
|
+
# NOTICE: For performance reasons, do not eager load the data if there is no search or
|
28
|
+
# filters on associations.
|
29
|
+
@records_count = @count_needs_includes ? @records.eager_load(@includes).count : @records.count
|
28
30
|
end
|
29
31
|
|
30
32
|
def query_for_batch
|
@@ -35,10 +37,18 @@ module ForestLiana
|
|
35
37
|
@records_sorted.offset(offset).limit(limit).to_a
|
36
38
|
end
|
37
39
|
|
38
|
-
def
|
39
|
-
|
40
|
+
def compute_includes
|
41
|
+
associations_has_one = SchemaUtils.one_associations(@resource)
|
40
42
|
.select { |association| SchemaUtils.model_included?(association.klass) }
|
41
|
-
|
43
|
+
|
44
|
+
includes = associations_has_one.each do |association|
|
45
|
+
if @tables_associated_to_relations_name[association.table_name].nil?
|
46
|
+
@tables_associated_to_relations_name[association.table_name] = []
|
47
|
+
end
|
48
|
+
@tables_associated_to_relations_name[association.table_name] << association.name
|
49
|
+
end
|
50
|
+
|
51
|
+
includes = associations_has_one.map(&:name)
|
42
52
|
includes_for_smart_search = []
|
43
53
|
|
44
54
|
if @collection && @collection.search_fields
|
@@ -54,9 +64,9 @@ module ForestLiana
|
|
54
64
|
end
|
55
65
|
|
56
66
|
if @field_names_requested
|
57
|
-
(includes & @field_names_requested).concat(includes_for_smart_search)
|
67
|
+
@includes = (includes & @field_names_requested).concat(includes_for_smart_search)
|
58
68
|
else
|
59
|
-
includes
|
69
|
+
@includes = includes
|
60
70
|
end
|
61
71
|
end
|
62
72
|
|
@@ -4,12 +4,13 @@ module ForestLiana
|
|
4
4
|
|
5
5
|
attr_reader :fields_searched
|
6
6
|
|
7
|
-
def initialize(params, includes, collection)
|
7
|
+
def initialize(params, includes, tables_associated_to_relations_name, collection)
|
8
8
|
@params = params
|
9
9
|
@includes = includes
|
10
10
|
@collection = collection
|
11
11
|
@fields_searched = []
|
12
12
|
@search = @params[:search]
|
13
|
+
@tables_associated_to_relations_name = tables_associated_to_relations_name
|
13
14
|
end
|
14
15
|
|
15
16
|
def perform(resource)
|
@@ -273,12 +274,22 @@ module ForestLiana
|
|
273
274
|
association_name_pluralized = association_name.pluralize
|
274
275
|
|
275
276
|
if [association_name, association_name_pluralized].include? association.table_name
|
276
|
-
# NOTICE: Default case. When the belongsTo association name and the referenced table name
|
277
|
+
# NOTICE: Default case. When the belongsTo association name and the referenced table name
|
278
|
+
# are identical.
|
277
279
|
association_name_for_condition = association.table_name
|
278
280
|
else
|
279
|
-
# NOTICE: When the the belongsTo association name and the referenced table name are
|
280
|
-
# Format with the ActiveRecord query generator style.
|
281
|
-
|
281
|
+
# NOTICE: When the the belongsTo association name and the referenced table name are not
|
282
|
+
# identical. Format with the ActiveRecord query generator style.
|
283
|
+
relations_on_this_table = @tables_associated_to_relations_name[association.table_name]
|
284
|
+
has_several_associations_to_the_table_and_is_not_first_one =
|
285
|
+
!relations_on_this_table.nil? && relations_on_this_table.size > 1 &&
|
286
|
+
relations_on_this_table.find_index(association.name) > 0
|
287
|
+
|
288
|
+
if has_several_associations_to_the_table_and_is_not_first_one
|
289
|
+
association_name_for_condition = "#{association_name_pluralized}_#{@resource.table_name}"
|
290
|
+
else
|
291
|
+
association_name_for_condition = association.table_name
|
292
|
+
end
|
282
293
|
end
|
283
294
|
|
284
295
|
@records.where("#{association_name_for_condition}.#{subfield} #{filter}")
|
@@ -5,14 +5,7 @@ module ForestLiana
|
|
5
5
|
def initialize(resource, params)
|
6
6
|
@resource = resource
|
7
7
|
@params = params
|
8
|
-
|
9
|
-
|
10
|
-
private
|
11
|
-
|
12
|
-
def includes
|
13
|
-
SchemaUtils.one_associations(@resource)
|
14
|
-
.select { |association| SchemaUtils.model_included?(association.klass) }
|
15
|
-
.map(&:name)
|
8
|
+
compute_includes()
|
16
9
|
end
|
17
10
|
end
|
18
11
|
end
|
@@ -4,8 +4,8 @@ module ForestLiana
|
|
4
4
|
|
5
5
|
def perform
|
6
6
|
return if @params[:aggregate].blank?
|
7
|
-
valueCurrent = get_resource().eager_load(includes)
|
8
|
-
valuePrevious = get_resource().eager_load(includes)
|
7
|
+
valueCurrent = get_resource().eager_load(@includes)
|
8
|
+
valuePrevious = get_resource().eager_load(@includes)
|
9
9
|
filter_date_interval = false
|
10
10
|
|
11
11
|
if @params[:filterType] && @params[:filters]
|
data/lib/forest_liana/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: forest_liana
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.0.pre.beta.
|
4
|
+
version: 3.0.0.pre.beta.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sandro Munda
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-02-
|
11
|
+
date: 2019-02-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|