jit_preloader 0.0.6 → 0.0.7
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/preloader.rb +2 -2
- data/lib/jit_preloader/version.rb +1 -1
- data/spec/lib/jit_preloader/preloader_spec.rb +6 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d26d02e1483223dda866884820aec9f06532e4a
|
4
|
+
data.tar.gz: c0d4c36e1c7300030113a3ca1ba4dfb22681a062
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 897e6e6246d4568fdef1f34dbe29c37a54a64b0d1ff58ff4d2cdc3dae7a9765ecf87d99f94247624666cdd099549b5ceea864336333d9719130299147d7bc3d2
|
7
|
+
data.tar.gz: a0d912d630bf11b8a7071a0a7949713eb6f67578735d186a53b18eb8d1f36fe89a5d289c0662c498196120d78b0a58e04558497aba3c1a2794712c669ac6ac6a
|
@@ -5,7 +5,7 @@ module JitPreloader
|
|
5
5
|
|
6
6
|
def self.attach(records)
|
7
7
|
new.tap do |loader|
|
8
|
-
loader.records = records
|
8
|
+
loader.records = records.dup
|
9
9
|
records.each do |record|
|
10
10
|
record.jit_preloader = loader
|
11
11
|
end
|
@@ -21,7 +21,7 @@ module JitPreloader
|
|
21
21
|
|
22
22
|
# We do not want the jit_preloader to be dumpable
|
23
23
|
# If you dump a ActiveRecord::Base object that has a jit_preloader instance variable
|
24
|
-
# you will also end up dumping all of the records the preloader has reference to.
|
24
|
+
# you will also end up dumping all of the records the preloader has reference to.
|
25
25
|
# Imagine getting N objects from a query and dumping each one of those into a cache
|
26
26
|
# each object would dump N+1 objects which means you'll end up storing O(N^2) memory. Thats no good.
|
27
27
|
# So instead, we will just nullify the jit_preloader on load
|
@@ -93,6 +93,12 @@ RSpec.describe JitPreloader::Preloader do
|
|
93
93
|
example.run
|
94
94
|
JitPreloader.globally_enabled = false
|
95
95
|
end
|
96
|
+
it "doesn't reference the same records array that is returned" do
|
97
|
+
contacts = Contact.all.to_a
|
98
|
+
contacts << "A string"
|
99
|
+
expect(contacts.first.jit_preloader.records).to eql Contact.all.to_a
|
100
|
+
end
|
101
|
+
|
96
102
|
context "when grabbing all of the address'es contries and email addresses" do
|
97
103
|
it "doesn't generate an N+1 query ntoification" do
|
98
104
|
ActiveSupport::Notifications.subscribed(callback, "n_plus_one_query") do
|
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: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kyle d'Oliveira
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -173,7 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
173
173
|
version: '0'
|
174
174
|
requirements: []
|
175
175
|
rubyforge_project:
|
176
|
-
rubygems_version: 2.
|
176
|
+
rubygems_version: 2.5.2
|
177
177
|
signing_key:
|
178
178
|
specification_version: 4
|
179
179
|
summary: Tool to understand N+1 queries and to remove them
|