goldiloader 4.0.0 → 4.0.1

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: 2b1702016efdeb47b12f583ff299bc46125714acc053b7c8594a9cf9a4fcba07
4
- data.tar.gz: 6485555c4d71199683907813d9563fdecce3c8bada819d7ae1180f48ad5afadb
3
+ metadata.gz: 3da0240495233f97f9762b4c81249b24fc6b9fb39e46801243e865ae2ed4d50d
4
+ data.tar.gz: d5bc7704557c4a9cdaf4e8d8e31d7d066444a964faf31812ce34117f845ccbeb
5
5
  SHA512:
6
- metadata.gz: 949fc36b600662dde9597b87c26430949bbdc12dff2d2eb9845405dcb273c2c9621edbb8d850f95dd602c892687dffc95849243bbd94c4e3473c31932f48464a
7
- data.tar.gz: 5d645a33f703ad458096af205535efcd5cebb2ab802ae0af8203cc6236f388a73d79ec0c08681c447dbbe4b057a29a0bd373c001ce277dd34285447614f138a8
6
+ metadata.gz: 73ab77e3c22b3e80dc903079dfe65245fceae13ab8b4fa1870705df1d1302eac82982523fad9cf7b9c2f4576022894ff16c8cd83b72d966ede5cd88ffb2b56d0
7
+ data.tar.gz: 402c5bfe96112e1a697af866205c3a16cb85966566adcac722deefc4ce4d487b4df10e335d1ce057cb2ddcf5ce4c8d490998c46b3e20feca4d98f334f2719534
@@ -68,23 +68,26 @@ module Goldiloader
68
68
  ActiveRecord::Relation::Merger.prepend(::Goldiloader::MergerPatch)
69
69
 
70
70
  module AssociationReflectionPatch
71
- def eager_loadable?
72
- return @eager_loadable if instance_variable_defined?(:@eager_loadable)
73
-
74
- @eager_loadable = if scope.nil?
75
- # Associations without any scoping options are eager loadable
76
- true
77
- elsif scope.arity > 0
78
- # The scope will be evaluated for every model instance so it can't
79
- # be eager loaded
80
- false
81
- else
82
- scope_info = Goldiloader::ScopeInfo.new(scope_for(klass.unscoped))
83
- scope_info.auto_include? &&
84
- !scope_info.limit? &&
85
- !scope_info.offset? &&
86
- (!has_one? || !scope_info.order?)
87
- end
71
+ # Note we need to pass the association's target class as an argument since it won't be known
72
+ # outside the context of an association instance for polymorphic associations.
73
+ def eager_loadable?(target_klass)
74
+ @eager_loadable_cache ||= Hash.new do |cache, target_klass_key|
75
+ cache[target_klass_key] = if scope.nil?
76
+ # Associations without any scoping options are eager loadable
77
+ true
78
+ elsif scope.arity > 0
79
+ # The scope will be evaluated for every model instance so it can't
80
+ # be eager loaded
81
+ false
82
+ else
83
+ scope_info = Goldiloader::ScopeInfo.new(scope_for(target_klass_key.unscoped))
84
+ scope_info.auto_include? &&
85
+ !scope_info.limit? &&
86
+ !scope_info.offset? &&
87
+ (!has_one? || !scope_info.order?)
88
+ end
89
+ end
90
+ @eager_loadable_cache[target_klass]
88
91
  end
89
92
  end
90
93
  ActiveRecord::Reflection::AssociationReflection.include(::Goldiloader::AssociationReflectionPatch)
@@ -111,7 +114,7 @@ module Goldiloader
111
114
  private
112
115
 
113
116
  def eager_loadable?
114
- reflection.eager_loadable? &&
117
+ klass && reflection.eager_loadable?(klass) &&
115
118
  (::Goldiloader::Compatibility.destroyed_model_associations_eager_loadable? || !owner.destroyed?)
116
119
  end
117
120
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Goldiloader
4
- VERSION = '4.0.0'
4
+ VERSION = '4.0.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: goldiloader
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 4.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel Turkel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-08 00:00:00.000000000 Z
11
+ date: 2021-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord