jsonapi-resources 0.10.0.beta7 → 0.10.0.beta8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jsonapi/active_relation/join_manager.rb +7 -7
- data/lib/jsonapi/active_relation_resource.rb +5 -1
- data/lib/jsonapi/basic_resource.rb +18 -2
- data/lib/jsonapi/configuration.rb +4 -0
- data/lib/jsonapi/link_builder.rb +6 -6
- data/lib/jsonapi/resource_serializer.rb +1 -1
- data/lib/jsonapi/resources/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: c8058151c97ec20cfa1d8d1606c19a0c24094fb7f70e27970772d5e0df5cc96b
|
4
|
+
data.tar.gz: 24604b487e967e5e24260e5d30d8a3f5891c6bf3fd1b1d8554a2f4eced9f503f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f486e212c1a44a440d4dad9b94c822a72e4080eca619e3838e8f4d1237223c882abf7f19c35cfa98af90a30d5f5799f79272f4393b0d8453134f7942fb14333
|
7
|
+
data.tar.gz: 299ed1970270e8d69deea9a5a4fe6f67909a915c0c76f1d0608b3ce0ff3d82dbe1676a74082677e65ff9f0cbfa4ba97dc4be88ef46ffe52bac8e42b36810fedf
|
@@ -154,13 +154,13 @@ module JSONAPI
|
|
154
154
|
next
|
155
155
|
end
|
156
156
|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
157
|
+
records, join_node = self.class.get_join_arel_node(records, options) {|records, options|
|
158
|
+
related_resource_klass.join_relationship(
|
159
|
+
records: records,
|
160
|
+
resource_type: related_resource_klass._type,
|
161
|
+
join_type: join_type,
|
162
|
+
relationship: relationship,
|
163
|
+
options: options)
|
164
164
|
}
|
165
165
|
|
166
166
|
details = {alias: self.class.alias_from_arel_node(join_node), join_type: join_type}
|
@@ -155,7 +155,7 @@ module JSONAPI
|
|
155
155
|
|
156
156
|
fragments = {}
|
157
157
|
rows = records.pluck(*pluck_fields)
|
158
|
-
rows.
|
158
|
+
rows.each do |row|
|
159
159
|
rid = JSONAPI::ResourceIdentity.new(resource_klass, pluck_fields.length == 1 ? row : row[0])
|
160
160
|
|
161
161
|
fragments[rid] ||= JSONAPI::ResourceFragment.new(rid)
|
@@ -181,6 +181,10 @@ module JSONAPI
|
|
181
181
|
end
|
182
182
|
end
|
183
183
|
|
184
|
+
if JSONAPI.configuration.warn_on_performance_issues && (rows.length > fragments.length)
|
185
|
+
warn "Performance issue detected: `#{self.name.to_s}.records` returned non-normalized results in `#{self.name.to_s}.find_fragments`."
|
186
|
+
end
|
187
|
+
|
184
188
|
fragments
|
185
189
|
end
|
186
190
|
|
@@ -453,6 +453,9 @@ module JSONAPI
|
|
453
453
|
|
454
454
|
subclass._routed = false
|
455
455
|
subclass._warned_missing_route = false
|
456
|
+
|
457
|
+
subclass._clear_cached_attribute_options
|
458
|
+
subclass._clear_fields_cache
|
456
459
|
end
|
457
460
|
|
458
461
|
def rebuild_relationships(relationships)
|
@@ -527,6 +530,9 @@ module JSONAPI
|
|
527
530
|
end
|
528
531
|
|
529
532
|
def attribute(attribute_name, options = {})
|
533
|
+
_clear_cached_attribute_options
|
534
|
+
_clear_fields_cache
|
535
|
+
|
530
536
|
attr = attribute_name.to_sym
|
531
537
|
|
532
538
|
check_reserved_attribute_name(attr)
|
@@ -693,7 +699,7 @@ module JSONAPI
|
|
693
699
|
end
|
694
700
|
|
695
701
|
def fields
|
696
|
-
_relationships.keys | _attributes.keys
|
702
|
+
@_fields_cache ||= _relationships.keys | _attributes.keys
|
697
703
|
end
|
698
704
|
|
699
705
|
def resources_for(records, context)
|
@@ -826,7 +832,7 @@ module JSONAPI
|
|
826
832
|
|
827
833
|
# quasi private class methods
|
828
834
|
def _attribute_options(attr)
|
829
|
-
default_attribute_options.merge(@_attributes[attr])
|
835
|
+
@_cached_attribute_options[attr] ||= default_attribute_options.merge(@_attributes[attr])
|
830
836
|
end
|
831
837
|
|
832
838
|
def _attribute_delegated_name(attr)
|
@@ -1063,6 +1069,8 @@ module JSONAPI
|
|
1063
1069
|
end
|
1064
1070
|
|
1065
1071
|
def _add_relationship(klass, *attrs)
|
1072
|
+
_clear_fields_cache
|
1073
|
+
|
1066
1074
|
options = attrs.extract_options!
|
1067
1075
|
options[:parent_resource] = self
|
1068
1076
|
|
@@ -1107,6 +1115,14 @@ module JSONAPI
|
|
1107
1115
|
@_relationships[name] = relationship_object
|
1108
1116
|
end
|
1109
1117
|
|
1118
|
+
def _clear_cached_attribute_options
|
1119
|
+
@_cached_attribute_options = {}
|
1120
|
+
end
|
1121
|
+
|
1122
|
+
def _clear_fields_cache
|
1123
|
+
@_fields_cache = nil
|
1124
|
+
end
|
1125
|
+
|
1110
1126
|
private
|
1111
1127
|
|
1112
1128
|
def check_reserved_resource_name(type, name)
|
@@ -10,6 +10,7 @@ module JSONAPI
|
|
10
10
|
:raise_if_parameters_not_allowed,
|
11
11
|
:warn_on_route_setup_issues,
|
12
12
|
:warn_on_missing_routes,
|
13
|
+
:warn_on_performance_issues,
|
13
14
|
:default_allow_include_to_one,
|
14
15
|
:default_allow_include_to_many,
|
15
16
|
:allow_sort,
|
@@ -60,6 +61,7 @@ module JSONAPI
|
|
60
61
|
|
61
62
|
self.warn_on_route_setup_issues = true
|
62
63
|
self.warn_on_missing_routes = true
|
64
|
+
self.warn_on_performance_issues = true
|
63
65
|
|
64
66
|
# :none, :offset, :paged, or a custom paginator name
|
65
67
|
self.default_paginator = :none
|
@@ -272,6 +274,8 @@ module JSONAPI
|
|
272
274
|
|
273
275
|
attr_writer :warn_on_missing_routes
|
274
276
|
|
277
|
+
attr_writer :warn_on_performance_issues
|
278
|
+
|
275
279
|
attr_writer :use_relationship_reflection
|
276
280
|
|
277
281
|
attr_writer :resource_cache
|
data/lib/jsonapi/link_builder.rb
CHANGED
@@ -123,16 +123,16 @@ module JSONAPI
|
|
123
123
|
end
|
124
124
|
|
125
125
|
def resources_path(source_klass)
|
126
|
-
|
126
|
+
@_resources_path ||= {}
|
127
|
+
@_resources_path[source_klass] ||= formatted_module_path_from_class(source_klass) + format_route(source_klass._type.to_s)
|
127
128
|
end
|
128
129
|
|
129
130
|
def resource_path(source)
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
131
|
+
if source.class.singleton?
|
132
|
+
resources_path(source.class)
|
133
|
+
else
|
134
|
+
"#{resources_path(source.class)}/#{source.id}"
|
134
135
|
end
|
135
|
-
url
|
136
136
|
end
|
137
137
|
|
138
138
|
def resource_url(source)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsonapi-resources
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.10.0.
|
4
|
+
version: 0.10.0.beta8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Gebhardt
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-07-
|
12
|
+
date: 2019-07-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|