jit_preloader 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jit_preloader/active_record/associations/collection_association.rb +1 -1
- data/lib/jit_preloader/active_record/associations/singular_association.rb +1 -1
- data/lib/jit_preloader/version.rb +1 -1
- data/spec/lib/jit_preloader/preloader_spec.rb +16 -0
- data/spec/support/models.rb +3 -0
- metadata +6 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b1347f4a6e1db52e169d10cb83f6c365867f04882c873c9d6fa11c72553c385
|
4
|
+
data.tar.gz: 90fd4451da01e450c484ff23eec4ac08f9adbc955559adfa57972a639c37fefc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5fbf30e83a2f31e93831930eb4d4c09d4dc42a75f753f43da8b62082867e8810845f41da09dca4e8e840c2fdae569e1b95d6af565239c55f30b8474c88505cf7
|
7
|
+
data.tar.gz: caf85a19d5a50f325a828fca0c6c3f55adb56345c9fe76afea48abf366706baac3268ec6d6584946516af9f94a3cfc04346f5a886f920d73c8c1a7df6599839a
|
@@ -4,7 +4,7 @@ module JitPreloader
|
|
4
4
|
def load_target
|
5
5
|
was_loaded = loaded?
|
6
6
|
|
7
|
-
if !loaded? && owner.persisted? && owner.jit_preloader
|
7
|
+
if !loaded? && owner.persisted? && owner.jit_preloader && (reflection.scope.nil? || reflection.scope.arity == 0)
|
8
8
|
owner.jit_preloader.jit_preload(reflection.name)
|
9
9
|
end
|
10
10
|
|
@@ -4,7 +4,7 @@ module JitPreloader
|
|
4
4
|
def load_target
|
5
5
|
was_loaded = loaded?
|
6
6
|
|
7
|
-
if !loaded? && owner.persisted? && owner.jit_preloader
|
7
|
+
if !loaded? && owner.persisted? && owner.jit_preloader && (reflection.scope.nil? || reflection.scope.arity == 0)
|
8
8
|
owner.jit_preloader.jit_preload(reflection.name)
|
9
9
|
end
|
10
10
|
|
@@ -202,6 +202,22 @@ RSpec.describe JitPreloader::Preloader do
|
|
202
202
|
end
|
203
203
|
end
|
204
204
|
|
205
|
+
context "when accessing an association with a scope that has a parameter" do
|
206
|
+
let!(:contact_book) { ContactBook.create(name: "The Yellow Pages") }
|
207
|
+
let!(:contact) { Contact.create(name: "Contact", contact_book: contact_book) }
|
208
|
+
let!(:company1) { Company.create(name: "Company1", contact_book: contact_book) }
|
209
|
+
|
210
|
+
it "is unable to be preloaded" do
|
211
|
+
ActiveSupport::Notifications.subscribed(callback, "n_plus_one_query") do
|
212
|
+
ContactBook.all.jit_preload.each do |contact_book|
|
213
|
+
expect(contact_book.contacts_with_scope.to_a).to eql [company1, contact]
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
expect(source_map).to eql(Hash[contact_book, [:contacts_with_scope]])
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
205
221
|
context "when preloading an aggregate on a polymorphic has_many through relationship" do
|
206
222
|
let(:contact_owner_addresses_counts) { [3] }
|
207
223
|
|
data/spec/support/models.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
class ContactBook < ActiveRecord::Base
|
2
2
|
has_many :contacts
|
3
|
+
has_many :contacts_with_scope, ->(_contact_book) { desc }, class_name: "Contact", foreign_key: :contact_book_id
|
3
4
|
has_many :employees, through: :contacts
|
4
5
|
|
5
6
|
has_many :companies
|
@@ -29,6 +30,8 @@ class Contact < ActiveRecord::Base
|
|
29
30
|
has_many_aggregate :addresses, :max_street_length, :maximum, "LENGTH(street)"
|
30
31
|
has_many_aggregate :phone_numbers, :count, :count, "id"
|
31
32
|
has_many_aggregate :addresses, :count, :count, "*"
|
33
|
+
|
34
|
+
scope :desc, ->{ order(id: :desc) }
|
32
35
|
end
|
33
36
|
|
34
37
|
class Company < Contact
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jit_preloader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kyle d'Oliveira
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-03-
|
11
|
+
date: 2021-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -178,7 +178,7 @@ homepage: ''
|
|
178
178
|
licenses:
|
179
179
|
- MIT
|
180
180
|
metadata: {}
|
181
|
-
post_install_message:
|
181
|
+
post_install_message:
|
182
182
|
rdoc_options: []
|
183
183
|
require_paths:
|
184
184
|
- lib
|
@@ -193,9 +193,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
193
193
|
- !ruby/object:Gem::Version
|
194
194
|
version: '0'
|
195
195
|
requirements: []
|
196
|
-
|
197
|
-
|
198
|
-
signing_key:
|
196
|
+
rubygems_version: 3.0.3
|
197
|
+
signing_key:
|
199
198
|
specification_version: 4
|
200
199
|
summary: Tool to understand N+1 queries and to remove them
|
201
200
|
test_files:
|