forest_liana 9.13.0 → 9.14.1
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/serializers/forest_liana/serializer_factory.rb +24 -6
- data/app/services/forest_liana/base_getter.rb +2 -1
- data/app/services/forest_liana/has_many_getter.rb +2 -0
- data/app/services/forest_liana/resources_getter.rb +41 -17
- data/lib/forest_liana/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e36ceb8802f17dd57f5c777b1d0c47570ee12259c78048735ad9bd75166e099d
|
4
|
+
data.tar.gz: 4eb56b56fb1392a0750f0e522676b15e34d83ae725b5218010685ca278b7d10b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8db001396703db0cd5277f501e93fa43efaf771baa8852e561d5dcf706a862e6bceaa20ababeed0702aae66ebea3961b33257308356a175e47ed2a08193364ff
|
7
|
+
data.tar.gz: 313aed4b4ac152cd4baba032f875016d1c87162a04e957851f4ed9495eebdf8104aaea238db0ea5442a7213661697d5b8acbcbaa2686f4ab4af83cd095ac0879
|
@@ -118,12 +118,6 @@ module ForestLiana
|
|
118
118
|
|
119
119
|
if ret[:href].blank?
|
120
120
|
begin
|
121
|
-
if @options[:include].try(:include?, attribute_name.to_s) &&
|
122
|
-
!SchemaHelper.is_smart_field?(object.class, attribute_name.to_s)
|
123
|
-
|
124
|
-
object.send(attribute_name)
|
125
|
-
end
|
126
|
-
|
127
121
|
SchemaUtils.many_associations(object.class).each do |a|
|
128
122
|
if a.name == attribute_name
|
129
123
|
ret[:href] = "/forest/#{ForestLiana.name_for(object.class)}/#{object.id}/relationships/#{attribute_name}"
|
@@ -137,6 +131,30 @@ module ForestLiana
|
|
137
131
|
ret
|
138
132
|
end
|
139
133
|
|
134
|
+
def has_one_relationships
|
135
|
+
return {} if self.class.to_one_associations.nil?
|
136
|
+
data = {}
|
137
|
+
self.class.to_one_associations.each do |attribute_name, attr_data|
|
138
|
+
relation = object.class.reflect_on_all_associations.find { |a| a.name == attribute_name }
|
139
|
+
|
140
|
+
next if !should_include_attr?(attribute_name, attr_data)
|
141
|
+
|
142
|
+
unless relation.nil? || (relation.respond_to?(:polymorphic?) && relation.polymorphic?)
|
143
|
+
relation_class_name = ForestLiana.name_for(relation.klass).demodulize
|
144
|
+
|
145
|
+
if object.respond_to?(relation.foreign_key.to_sym) &&
|
146
|
+
@options[:fields][relation_class_name]&.size == 1 &&
|
147
|
+
@options[:fields][relation_class_name]&.include?(relation.klass.primary_key.to_sym)
|
148
|
+
|
149
|
+
attr_data[:attr_or_block] = proc { relation.klass.new(relation.klass.primary_key => object.send(relation.foreign_key.to_sym)) }
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
data[attribute_name] = attr_data
|
154
|
+
end
|
155
|
+
data
|
156
|
+
end
|
157
|
+
|
140
158
|
private
|
141
159
|
|
142
160
|
def intercom_integration?
|
@@ -19,11 +19,12 @@ module ForestLiana
|
|
19
19
|
|
20
20
|
def compute_includes
|
21
21
|
@includes = ForestLiana::QueryHelper.get_one_association_names_symbol(@resource)
|
22
|
+
@optional_includes = []
|
22
23
|
end
|
23
24
|
|
24
25
|
def optimize_record_loading(resource, records, force_preload = true)
|
25
26
|
polymorphic, preload_loads = analyze_associations(resource)
|
26
|
-
result = records.eager_load(@includes.uniq - preload_loads - polymorphic)
|
27
|
+
result = records.eager_load(@includes.uniq - preload_loads - polymorphic - @optional_includes)
|
27
28
|
|
28
29
|
result = result.preload(preload_loads) if Rails::VERSION::MAJOR >= 7 && force_preload
|
29
30
|
|
@@ -31,7 +31,7 @@ module ForestLiana
|
|
31
31
|
|
32
32
|
def perform
|
33
33
|
polymorphic_association, preload_loads = analyze_associations(@resource)
|
34
|
-
includes = @includes.uniq - polymorphic_association - preload_loads
|
34
|
+
includes = @includes.uniq - polymorphic_association - preload_loads - @optional_includes
|
35
35
|
has_smart_fields = @params[:fields][@collection_name].split(',').any? do |field|
|
36
36
|
ForestLiana::SchemaHelper.is_smart_field?(@resource, field)
|
37
37
|
end
|
@@ -56,10 +56,22 @@ module ForestLiana
|
|
56
56
|
|
57
57
|
def records
|
58
58
|
records = @records.offset(offset).limit(limit).to_a
|
59
|
-
|
60
59
|
polymorphic_association, preload_loads = analyze_associations(@resource)
|
60
|
+
|
61
61
|
if polymorphic_association && Rails::VERSION::MAJOR >= 7
|
62
|
-
|
62
|
+
preloader = ActiveRecord::Associations::Preloader.new(records: records, associations: polymorphic_association)
|
63
|
+
preloader.loaders
|
64
|
+
preloader.branches.each do |branch|
|
65
|
+
branch.loaders.each do |loader|
|
66
|
+
records_by_owner = loader.records_by_owner
|
67
|
+
records_by_owner.each do |record, association|
|
68
|
+
record_index = records.find_index { |r| r.id == record.id }
|
69
|
+
records[record_index].define_singleton_method(branch.association) do
|
70
|
+
association.first
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
63
75
|
end
|
64
76
|
|
65
77
|
preload_cross_database_associations(records, preload_loads)
|
@@ -132,26 +144,38 @@ module ForestLiana
|
|
132
144
|
|
133
145
|
def compute_includes
|
134
146
|
associations_has_one = ForestLiana::QueryHelper.get_one_associations(@resource)
|
147
|
+
@optional_includes = []
|
148
|
+
if @field_names_requested
|
149
|
+
includes = associations_has_one.map do |association|
|
150
|
+
association_name = association.name.to_s
|
135
151
|
|
136
|
-
|
137
|
-
|
152
|
+
if @params[:fields].key?(association_name) &&
|
153
|
+
@params[:fields][association_name].split(',').size == 1 &&
|
154
|
+
@params[:fields][association_name].split(',').include?(association.klass.primary_key)
|
138
155
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
.map { |field| field.split('.').first.to_sym }
|
156
|
+
@field_names_requested << association.foreign_key
|
157
|
+
@optional_includes << association.name
|
158
|
+
end
|
143
159
|
|
144
|
-
|
145
|
-
|
146
|
-
.map(&:name)
|
160
|
+
association.name
|
161
|
+
end
|
147
162
|
|
148
|
-
includes_for_smart_search =
|
149
|
-
|
163
|
+
includes_for_smart_search = []
|
164
|
+
if @collection && @collection.search_fields
|
165
|
+
includes_for_smart_search = @collection.search_fields
|
166
|
+
.select { |field| field.include? '.' }
|
167
|
+
.map { |field| field.split('.').first.to_sym }
|
168
|
+
|
169
|
+
includes_has_many = SchemaUtils.many_associations(@resource)
|
170
|
+
.select { |association| SchemaUtils.model_included?(association.klass) }
|
171
|
+
.map(&:name)
|
172
|
+
|
173
|
+
includes_for_smart_search = includes_for_smart_search & includes_has_many
|
174
|
+
end
|
150
175
|
|
151
|
-
if @field_names_requested
|
152
176
|
@includes = (includes & @field_names_requested).concat(includes_for_smart_search)
|
153
177
|
else
|
154
|
-
@includes =
|
178
|
+
@includes = associations_has_one.map(&:name)
|
155
179
|
end
|
156
180
|
end
|
157
181
|
|
@@ -298,7 +322,7 @@ module ForestLiana
|
|
298
322
|
|
299
323
|
def compute_select_fields
|
300
324
|
select = ['_forest_admin_eager_load']
|
301
|
-
@
|
325
|
+
@field_names_requested.each do |path|
|
302
326
|
association = get_one_association(path)
|
303
327
|
if association
|
304
328
|
while association.options[:through]
|
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: 9.
|
4
|
+
version: 9.14.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sandro Munda
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-05-
|
11
|
+
date: 2025-05-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|