jpie 4.1.4 → 4.1.5

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: eb96ac4995c6800cd07f48cd102d03820072ca58b8f1db35fcc54dece961a281
4
- data.tar.gz: 7dfa2d854082e1b4848b94230a0ae06606751019c0b239308c4f57dc14027a7b
3
+ metadata.gz: 618cb164f0b64934d5cd9a0c6e871b726bcc6b40f4add24c3204bea490a0cd5c
4
+ data.tar.gz: f4acc02e6f57760deae01dc2d4c49acb29fb5273acefb3eac290f7519e3f53d4
5
5
  SHA512:
6
- metadata.gz: 2e87c64831d1acbeaa40a4d0d91e2741e0d34c30585903ef7fe7d266daaa0359078549592eb1ae516a4dab9879a2d5e2e45b59ba452e797d4a6f3fe4014714c8
7
- data.tar.gz: f4dba819c5a1e0b04997e623ce83bf568050e80842b93a75547b02be2232813d9f0f060cfb643d50c693c66bacf7785ae4fc071863748bd4241e5f7ff71460e7
6
+ metadata.gz: b83a3b08c429dc700144718b112c578bb9c67243a05a2400ef7fdd9055f614e50852e4819bd63c6897e04cf168eee09e1f7d2b606da39340b9dc6acd2e723b8a
7
+ data.tar.gz: 79f17c229521c0c99541e9787e298e9e00268996759ca8a54f67fec95f212f3cd7f124ea672d8c9da65f65546c6ad02794c971b49a8a8fef7b874883eb601760
data/CHANGELOG.md CHANGED
@@ -7,6 +7,20 @@ at release time.
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [4.1.5] - 2026-11-11
11
+
12
+ ### Fixed
13
+
14
+ - **Run resource preloads once for the subclasses of a polymorphic hop.** The
15
+ include preload step grouped the targets of a hop by exact class and ran the
16
+ `records` preloads of the resource once for each class. Five STI subclasses
17
+ that share one preload set ran each preload five times. The step now groups
18
+ the targets by the preloads their resource declares. Classes that share a
19
+ preload set run each preload once for all their records. A mixed STI set on
20
+ a hop that is not polymorphic now gets the preloads of every subclass. The
21
+ response does not change. Regression spec:
22
+ `polymorphic_sti_resource_preload_spec.rb`.
23
+
10
24
  ## [4.1.4] - 2026-11-10
11
25
 
12
26
  ### Fixed
@@ -66,7 +66,7 @@ module JSONAPI
66
66
  targets = collect_include_targets(records, association_name)
67
67
  next if targets.empty?
68
68
 
69
- apply_preloads_for_targets(targets, reflection.polymorphic?)
69
+ apply_resource_preloads(targets)
70
70
  next if subtree.empty?
71
71
 
72
72
  descend_resource_tree(targets, reflection, subtree)
@@ -85,11 +85,13 @@ module JSONAPI
85
85
  end
86
86
  end
87
87
 
88
- def apply_preloads_for_targets(targets, polymorphic)
89
- if polymorphic
90
- targets.group_by(&:class).each_value { |recs| apply_resource_preloads(recs) }
91
- else
92
- apply_resource_preloads(targets)
88
+ # Groups the targets by the preloads their resource declares, so classes that share them
89
+ # (STI subclasses and sibling resources) run each preload once for all their records.
90
+ def apply_resource_preloads(targets)
91
+ groups = Hash.new { |hash, values| hash[values] = [] }
92
+ targets.group_by(&:class).each { |klass, records| groups[resource_preload_values(klass)].concat(records) }
93
+ groups.each do |values, records|
94
+ ActiveRecord::Associations::Preloader.new(records:, associations: values).call unless values.empty?
93
95
  end
94
96
  end
95
97
 
@@ -100,15 +102,9 @@ module JSONAPI
100
102
  end.compact.uniq
101
103
  end
102
104
 
103
- def apply_resource_preloads(records)
104
- return if records.empty?
105
-
106
- klass = records.first.class
107
- resource_scope = ResourceLoader.find_for_model(klass, namespace: jsonapi_namespace).records
108
- preload_values = resource_scope.preload_values + resource_scope.includes_values
109
- return if preload_values.empty?
110
-
111
- ActiveRecord::Associations::Preloader.new(records:, associations: preload_values).call
105
+ def resource_preload_values(klass)
106
+ scope = ResourceLoader.find_for_model(klass, namespace: jsonapi_namespace).records
107
+ scope.preload_values + scope.includes_values
112
108
  end
113
109
  end
114
110
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JSONAPI
4
- VERSION = "4.1.4"
4
+ VERSION = "4.1.5"
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: 4.1.4
4
+ version: 4.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emil Kampp