identity_cache 1.5.3 → 1.5.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: def26128f16258d40ae0aab05bff51da07f3e6290d7742562a968cb061b4e4fa
4
- data.tar.gz: 5422730f52bed62f919d697c393fc2ead2de6b59edff35f6f6d02f032322c0a9
3
+ metadata.gz: 8a7b8ac895d1bdef7695e310042d3699d5d9b279c12d538eb3a577b51cc27acd
4
+ data.tar.gz: a423c92964c108f8038202ac4ef996697023b39c2db445635d4365a7d81e19fb
5
5
  SHA512:
6
- metadata.gz: 373cb5c7745fa34fd3b512a34ef8646fe3405082f2c174bdc23538827e024180a0275717a9ca7b3c82dd4dbb8ef1847d107a65ccecc5cb253a8608ab68507a60
7
- data.tar.gz: d7764abbbeaee3b3d48f04d1c9ff2309a18a7eb7fbc3b4a5a2e868a3444ff8e9e2d81776a6f0e9d2d68814fa938de7dce35ab65c8538d7ac313f05bc86f28381
6
+ metadata.gz: 65487956cfd97f17abcf90bf6055283fe0b3840a5f01a82d69e570638c4f8cd10a75cda05a9b80c1eb0f6013d8f41a3f5b94a451417cd16c57e16b7ef4fa6081
7
+ data.tar.gz: aa8ec598d2854332aa7054be7c4af26ec7c85271f15cd26b9967a74493e5ec7f91e636369ff0f144699f0ab9f1c719477713c5f069b7379f224c1e67d0c7c561
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 1.5.4
6
+
7
+ - Make `prefetch_associations` work as expected on associations that have been partially prefetched
8
+
5
9
  ## 1.5.3
6
10
 
7
11
  - No longer call `should_use_cache?` on embedded/prefetched associations when reading values
@@ -14,7 +14,7 @@ module IdentityCache
14
14
  ensure_base_model
15
15
 
16
16
  unless (reflection = reflect_on_association(association))
17
- raise AssociationError, "Association named '#{association}' was not found on #{self.class}"
17
+ raise AssociationError, "Association named '#{association}' was not found on #{self}"
18
18
  end
19
19
 
20
20
  if reflection.scope
@@ -77,16 +77,20 @@ module IdentityCache
77
77
  end
78
78
  end
79
79
 
80
- load_strategy.load_multi(
81
- reflection.klass.cached_primary_index,
82
- ids_to_owner_record.keys
83
- ) do |associated_records_by_id|
84
- associated_records_by_id.each do |id, associated_record|
85
- owner_record = ids_to_owner_record.fetch(id)
86
- write(owner_record, associated_record)
87
- end
80
+ if ids_to_owner_record.any?
81
+ load_strategy.load_multi(
82
+ reflection.klass.cached_primary_index,
83
+ ids_to_owner_record.keys
84
+ ) do |associated_records_by_id|
85
+ associated_records_by_id.each do |id, associated_record|
86
+ owner_record = ids_to_owner_record.fetch(id)
87
+ write(owner_record, associated_record)
88
+ end
88
89
 
89
- yield associated_records_by_id.values.compact
90
+ yield associated_records_by_id.values.compact
91
+ end
92
+ else
93
+ yield records.filter_map { |record| record.instance_variable_get(records_variable_name) }
90
94
  end
91
95
  end
92
96
  end
@@ -143,7 +143,7 @@ module IdentityCache
143
143
 
144
144
  def check_association_for_caching(association)
145
145
  unless (association_reflection = reflect_on_association(association))
146
- raise AssociationError, "Association named '#{association}' was not found on #{self.class}"
146
+ raise AssociationError, "Association named '#{association}' was not found on #{self}"
147
147
  end
148
148
  if association_reflection.options[:through]
149
149
  raise UnsupportedAssociationError, "caching through associations isn't supported"
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IdentityCache
4
- VERSION = "1.5.3"
4
+ VERSION = "1.5.4"
5
5
  CACHE_VERSION = 8
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: identity_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.3
4
+ version: 1.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Camilo Lopez
@@ -14,7 +14,7 @@ authors:
14
14
  autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
- date: 2024-01-22 00:00:00.000000000 Z
17
+ date: 2024-02-20 00:00:00.000000000 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: activerecord
@@ -190,7 +190,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
190
190
  - !ruby/object:Gem::Version
191
191
  version: '0'
192
192
  requirements: []
193
- rubygems_version: 3.5.4
193
+ rubygems_version: 3.5.6
194
194
  signing_key:
195
195
  specification_version: 4
196
196
  summary: IdentityCache lets you specify how you want to cache your model objects,