jpie 3.1.6 → 3.5.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ac6d32dde9d9be0163f1f3c48a9c65770f4465176a403efdb5f0ba42f18bb4f5
4
- data.tar.gz: 4ac43aa7aaf9194497910650cc1180800952806a7cb5ebf1ecf590decda4aaa0
3
+ metadata.gz: c54015e01586dd3a4a6f14430928d231e1e6ce8f1e46a9cefa54ab7c93d45226
4
+ data.tar.gz: 90f24a271244366daf7ff47dd7a20a79740baf72c037b4f9ff428bd7a69bde33
5
5
  SHA512:
6
- metadata.gz: ec7aff7ee080d6acca4bcf19cd3d72f7084c3bcb492df1d6e5c4b674711575450bd03e558267889d46cc9c436255dbc3013fc1b5bfa3df074503fdb39f342737
7
- data.tar.gz: 6a4c2811e9df0bad8bbecc8b6a62ae5a0f9e44912d0035fad7c22a6569b383e24b574dbb35fe2cc3c9402b8157079af4f0addbef91e685e997539200c9b317b5
6
+ metadata.gz: bd1e8f0ce88654ca8c594f9b58cb4320ecfeba576d5f21062e0136737c0bbabd24a3aef94f899ad0732a7f363f9115e1e602c9079b930aa7159187b90e834a61
7
+ data.tar.gz: ba4d97f2a60f0b73ca1480de68cdfb05c992e2434bff55ee6569da74447788c7f1c51e7ac2047126976adca6ba1a88a9b8c4fd6e9e60a7b1cddd7aa26ac379e7
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jpie (3.1.5)
4
+ jpie (3.1.6)
5
5
  actionpack (~> 8.1, >= 8.1.0)
6
6
  pg_query (>= 4)
7
7
  prosopite (>= 1)
@@ -22,7 +22,11 @@ module JSONAPI
22
22
  return scope if scope.is_a?(Array)
23
23
 
24
24
  inc_hash = includes_to_hash(includes)
25
- hash_contains_polymorphic?(inc_hash, model_class) ? scope.preload(inc_hash) : scope.includes(inc_hash)
25
+ # `includes` may resolve to a JOIN when the base scope already references an
26
+ # associated table (e.g. a `records` override that sorts by one). Rails cannot
27
+ # eager-load polymorphic or instance-dependent associations in a JOIN, so those
28
+ # must go through `preload` (a separate query), which loads them without raising.
29
+ preload_required?(inc_hash, model_class) ? scope.preload(inc_hash) : scope.includes(inc_hash)
26
30
  end
27
31
 
28
32
  def filter_includable(hash, klass)
@@ -34,6 +38,24 @@ module JSONAPI
34
38
  end
35
39
  end
36
40
 
41
+ def preload_required?(hash, klass)
42
+ hash.any? do |key, value|
43
+ assoc = klass.reflect_on_association(key)
44
+ next false unless assoc
45
+
46
+ assoc.polymorphic? || instance_dependent_scope?(assoc) ||
47
+ (value.present? && preload_required?(value, assoc.klass))
48
+ end
49
+ end
50
+
51
+ # Rails refuses to eager-load (JOIN) an association whose scope takes the owner
52
+ # instance (`->(owner) { ... }`), raising "instance dependent scopes are not
53
+ # supported". Its arity is non-zero; such associations must be preloaded instead.
54
+ def instance_dependent_scope?(assoc)
55
+ scope = assoc.scope
56
+ !scope.nil? && scope.arity != 0
57
+ end
58
+
37
59
  def hash_contains_polymorphic?(hash, klass)
38
60
  hash.any? { |key, value| polymorphic_in_hash_entry?(key, value, klass) }
39
61
  end
@@ -35,7 +35,7 @@ module JSONAPI
35
35
  parts = n1_details.split("Call stack:")
36
36
  return nil if parts.size < 2
37
37
 
38
- query_section = parts[0].sub(/\AN\+1 queries detected:\n?/, "")
38
+ query_section = parts[0].sub(/\AN\+1 queries detected(?: \([\d.]+ms\))?:\n?/, "")
39
39
  first_line = query_section.each_line.map(&:strip).reject(&:empty?).first
40
40
  first_line.presence
41
41
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JSONAPI
4
- VERSION = "3.1.6"
4
+ VERSION = "3.5.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jpie
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.6
4
+ version: 3.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emil Kampp
@@ -219,7 +219,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
219
219
  - !ruby/object:Gem::Version
220
220
  version: '0'
221
221
  requirements: []
222
- rubygems_version: 3.7.2
222
+ rubygems_version: 3.6.9
223
223
  specification_version: 4
224
224
  summary: JSON:API compliant Rails gem for producing and consuming JSON:API resources
225
225
  test_files: []