jpie 4.1.0 → 4.1.1.pre.202609280317

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: 5c04100490b218fa6dbef0035d581acd97ec7ebae03d045d0966a633bdcfb567
4
- data.tar.gz: 116d6e4ae7f51f03a47f8222771f2fb508435fce759014eadd3a02642a4f7b85
3
+ metadata.gz: 89f25c649293b22832412f92bcf29361b881deaf953d6b2db661736e226abd8d
4
+ data.tar.gz: 4256bc8778bf8968c852fb901f753fe433b3ed21776a02ea2445f86f179a05c2
5
5
  SHA512:
6
- metadata.gz: e86bd604abba1b02e6148d857a2967a05b90a35c796503f2517d25368cbb95a8c102afddc2208a8f77961085bc041a55e27e6b6d0f304b37ed9404362fbf64eb
7
- data.tar.gz: 3ec3bda5b8ce2e07fb494f790cbc20391b37fd12a9f57c6a352b3129a9037246116d68440f70cb86b17e3ca424ad6bd4efdbba174b3af8825cb1149bfc59fbb5
6
+ metadata.gz: 5384c6655800b556886f7ba54510c982fb2432fdcdde2439c1ce90f5d77bd10de6094973e0f6bed8c01f22a32c064de5c255b133c87c2395cbc4c12f9948e9b4
7
+ data.tar.gz: 9b72004eb39131a37d9e289e9c0103f88f17ebffd48df26a5ff0ee93337af855e7932c1965468a2d8ca0a4300180dba6e37897964cc124e26d2076cfe2aff536
data/CHANGELOG.md CHANGED
@@ -7,6 +7,19 @@ at release time.
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ### Fixed
11
+
12
+ - **Vet a partial where hash in the database, not in memory.**
13
+ `IncludeFilterCache#filter` matched sideloaded records against
14
+ `where_values_hash`. That hash holds only the conditions ActiveRecord
15
+ expresses as a hash, and drops `where.not`, raw SQL, joins and ranges. A
16
+ resource whose `records` scope mixed both kinds lost the half the hash could
17
+ not carry, so an `?include=` surfaced records the related endpoint hides. The
18
+ hash now stands in for the scope only when it reproduces the whole where
19
+ clause; otherwise `filter` and `warm` vet ids in the database against the
20
+ full scope. Regression spec:
21
+ `include_filter_partial_where_hash_bypass_spec.rb`.
22
+
10
23
  ## [4.1.0] - 2026-09-15
11
24
 
12
25
  ### Fixed
@@ -76,12 +76,29 @@ module JSONAPI
76
76
  handler.call(controller: @authorization_context, scope:, action: :index, model_class: klass)
77
77
  end
78
78
 
79
+ # The hash stands in for the scope only when it reproduces the whole where
80
+ # clause. `where_values_hash` keeps the conditions ActiveRecord expresses
81
+ # as a hash and drops the rest: `where.not`, raw SQL, joins and ranges. A
82
+ # scope that mixes both kinds would otherwise lose the half the hash
83
+ # cannot carry, and an include would surface records the related endpoint
84
+ # hides. Return {} for a partial hash, so #filter and #warm vet ids in the
85
+ # database against the full scope.
79
86
  def where_hash_for(scope, klass)
80
- scope.where_values_hash(klass.table_name)
87
+ hash = scope.where_values_hash(klass.table_name)
88
+ return {} if hash.blank?
89
+
90
+ whole_clause?(scope, hash) ? hash : {}
81
91
  rescue StandardError
82
92
  {}
83
93
  end
84
94
 
95
+ # Rebuilds the clause from the hash on the same relation and compares the
96
+ # SQL. Rebuilding on `klass.unscoped` instead would repeat the condition
97
+ # an STI subclass already carries, and read every STI resource as partial.
98
+ def whole_clause?(scope, hash)
99
+ scope.unscope(:where).where(hash).only(:where).to_sql == scope.only(:where).to_sql
100
+ end
101
+
85
102
  def matches_where_hash?(record, hash)
86
103
  hash.all? do |attr, val|
87
104
  r_val = record.read_attribute(attr)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JSONAPI
4
- VERSION = "4.1.0"
4
+ VERSION = "4.1.1.pre.202609280317"
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.0
4
+ version: 4.1.1.pre.202609280317
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emil Kampp