jit_preloader 1.0.3 → 1.0.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: e5cc23052a16564dfac2f68f6668197ceda450b77fa83f87b0d33dc11138a863
4
- data.tar.gz: 35f074caa0985696872a9bdb56f48f966897715b6ad2db5545b5c3d08d01117b
3
+ metadata.gz: 515aa37a3edcd60ff85c7490bf7a96906a612c7b5645d3d81542c5e7997a9026
4
+ data.tar.gz: 4cab1990cd0346da95d0d0785d28b18d5db95fecf66dbfcf14be26d0b020af5d
5
5
  SHA512:
6
- metadata.gz: b5df602d53a93602c2733ace0a78ff16e0c1e2ea8958aa2585e56a7c119637f6d6e033761a710e66fb0c69e6c03701a264faf2e605c4eaf88333ccb2c860f9d7
7
- data.tar.gz: 3b64bdcde548bb182088294b14d1e239e825b92dc3b43772839e2967e6da64900360c84dea1d0578251262511333a55a42c57d948d101af032235a417e9c3e3a
6
+ metadata.gz: bf81adb00759b36e3bea5dfcaf9431c3259cac06412b57008e799585c7094d97073f836300a9631bd24fa0de7820874646861e7ea68e27cb773662d2e3826dec
7
+ data.tar.gz: b96b45f91474ca01a5235d5ba071c750268e7c029fcfa371c308747433a5cb9f54bfb2560a99051c335352c8a536a01887ae01bb840337ee2e9ab3a808f5ec84
@@ -0,0 +1,3 @@
1
+ # Own any files in the .github/workflows directory and any of its
2
+ # subdirectories.
3
+ /.github/workflows/ @clio/application-security @clio/penguins
@@ -0,0 +1,31 @@
1
+ name: Ruby Gem
2
+
3
+ on:
4
+ workflow_dispatch:
5
+ release:
6
+ types: [ published ]
7
+
8
+ jobs:
9
+ build:
10
+ name: Build + Publish
11
+ runs-on: ubuntu-latest
12
+ permissions:
13
+ contents: read
14
+
15
+ steps:
16
+ - uses: actions/checkout@v2
17
+ - name: Set up Ruby 2.7
18
+ uses: actions/setup-ruby@v1
19
+ with:
20
+ ruby-version: 2.7.x
21
+
22
+ - name: Publish to RubyGems
23
+ env:
24
+ GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
25
+ run: |
26
+ mkdir -p $HOME/.gem
27
+ touch $HOME/.gem/credentials
28
+ chmod 0600 $HOME/.gem/credentials
29
+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
30
+ gem build *.gemspec
31
+ gem push *.gem
data/Gemfile.5.2 ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem "activerecord", "~>5.2"
4
+
5
+ # Specify your gem's dependencies in jit_preloader.gemspec
6
+ gemspec
data/Gemfile.5.2.lock ADDED
@@ -0,0 +1,72 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ jit_preloader (1.0.3)
5
+ activerecord (>= 5.2, < 7)
6
+ activesupport
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activemodel (5.2.6)
12
+ activesupport (= 5.2.6)
13
+ activerecord (5.2.6)
14
+ activemodel (= 5.2.6)
15
+ activesupport (= 5.2.6)
16
+ arel (>= 9.0)
17
+ activesupport (5.2.6)
18
+ concurrent-ruby (~> 1.0, >= 1.0.2)
19
+ i18n (>= 0.7, < 2)
20
+ minitest (~> 5.1)
21
+ tzinfo (~> 1.1)
22
+ arel (9.0.0)
23
+ byebug (11.1.3)
24
+ concurrent-ruby (1.1.9)
25
+ database_cleaner (2.0.1)
26
+ database_cleaner-active_record (~> 2.0.0)
27
+ database_cleaner-active_record (2.0.1)
28
+ activerecord (>= 5.a)
29
+ database_cleaner-core (~> 2.0.0)
30
+ database_cleaner-core (2.0.1)
31
+ db-query-matchers (0.10.0)
32
+ activesupport (>= 4.0, < 7)
33
+ rspec (~> 3.0)
34
+ diff-lcs (1.4.4)
35
+ i18n (1.8.10)
36
+ concurrent-ruby (~> 1.0)
37
+ minitest (5.14.4)
38
+ rake (13.0.6)
39
+ rspec (3.10.0)
40
+ rspec-core (~> 3.10.0)
41
+ rspec-expectations (~> 3.10.0)
42
+ rspec-mocks (~> 3.10.0)
43
+ rspec-core (3.10.1)
44
+ rspec-support (~> 3.10.0)
45
+ rspec-expectations (3.10.1)
46
+ diff-lcs (>= 1.2.0, < 2.0)
47
+ rspec-support (~> 3.10.0)
48
+ rspec-mocks (3.10.2)
49
+ diff-lcs (>= 1.2.0, < 2.0)
50
+ rspec-support (~> 3.10.0)
51
+ rspec-support (3.10.2)
52
+ sqlite3 (1.4.2)
53
+ thread_safe (0.3.6)
54
+ tzinfo (1.2.9)
55
+ thread_safe (~> 0.1)
56
+
57
+ PLATFORMS
58
+ x86_64-darwin-19
59
+
60
+ DEPENDENCIES
61
+ activerecord (~> 5.2)
62
+ bundler
63
+ byebug
64
+ database_cleaner
65
+ db-query-matchers
66
+ jit_preloader!
67
+ rake (~> 13.0)
68
+ rspec
69
+ sqlite3
70
+
71
+ BUNDLED WITH
72
+ 2.2.12
data/Gemfile.6.0 ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem "activerecord", "~>6.0.0"
4
+
5
+ # Specify your gem's dependencies in jit_preloader.gemspec
6
+ gemspec
data/Gemfile.6.0.lock ADDED
@@ -0,0 +1,72 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ jit_preloader (1.0.3)
5
+ activerecord (>= 5.2, < 7)
6
+ activesupport
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activemodel (6.0.4.1)
12
+ activesupport (= 6.0.4.1)
13
+ activerecord (6.0.4.1)
14
+ activemodel (= 6.0.4.1)
15
+ activesupport (= 6.0.4.1)
16
+ activesupport (6.0.4.1)
17
+ concurrent-ruby (~> 1.0, >= 1.0.2)
18
+ i18n (>= 0.7, < 2)
19
+ minitest (~> 5.1)
20
+ tzinfo (~> 1.1)
21
+ zeitwerk (~> 2.2, >= 2.2.2)
22
+ byebug (11.1.3)
23
+ concurrent-ruby (1.1.9)
24
+ database_cleaner (2.0.1)
25
+ database_cleaner-active_record (~> 2.0.0)
26
+ database_cleaner-active_record (2.0.1)
27
+ activerecord (>= 5.a)
28
+ database_cleaner-core (~> 2.0.0)
29
+ database_cleaner-core (2.0.1)
30
+ db-query-matchers (0.10.0)
31
+ activesupport (>= 4.0, < 7)
32
+ rspec (~> 3.0)
33
+ diff-lcs (1.4.4)
34
+ i18n (1.8.10)
35
+ concurrent-ruby (~> 1.0)
36
+ minitest (5.14.4)
37
+ rake (13.0.6)
38
+ rspec (3.10.0)
39
+ rspec-core (~> 3.10.0)
40
+ rspec-expectations (~> 3.10.0)
41
+ rspec-mocks (~> 3.10.0)
42
+ rspec-core (3.10.1)
43
+ rspec-support (~> 3.10.0)
44
+ rspec-expectations (3.10.1)
45
+ diff-lcs (>= 1.2.0, < 2.0)
46
+ rspec-support (~> 3.10.0)
47
+ rspec-mocks (3.10.2)
48
+ diff-lcs (>= 1.2.0, < 2.0)
49
+ rspec-support (~> 3.10.0)
50
+ rspec-support (3.10.2)
51
+ sqlite3 (1.4.2)
52
+ thread_safe (0.3.6)
53
+ tzinfo (1.2.9)
54
+ thread_safe (~> 0.1)
55
+ zeitwerk (2.4.2)
56
+
57
+ PLATFORMS
58
+ x86_64-darwin-19
59
+
60
+ DEPENDENCIES
61
+ activerecord (~> 6.0.0)
62
+ bundler
63
+ byebug
64
+ database_cleaner
65
+ db-query-matchers
66
+ jit_preloader!
67
+ rake (~> 13.0)
68
+ rspec
69
+ sqlite3
70
+
71
+ BUNDLED WITH
72
+ 2.2.12
data/Gemfile.6.1 ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem "activerecord", "~>6.1"
4
+
5
+ # Specify your gem's dependencies in jit_preloader.gemspec
6
+ gemspec
data/Gemfile.6.1.lock ADDED
@@ -0,0 +1,72 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ jit_preloader (1.0.3)
5
+ activerecord (>= 5.2, < 7)
6
+ activesupport
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activemodel (6.1.4.1)
12
+ activesupport (= 6.1.4.1)
13
+ activerecord (6.1.4.1)
14
+ activemodel (= 6.1.4.1)
15
+ activesupport (= 6.1.4.1)
16
+ activesupport (6.1.4.1)
17
+ concurrent-ruby (~> 1.0, >= 1.0.2)
18
+ i18n (>= 1.6, < 2)
19
+ minitest (>= 5.1)
20
+ tzinfo (~> 2.0)
21
+ zeitwerk (~> 2.3)
22
+ byebug (11.1.3)
23
+ concurrent-ruby (1.1.9)
24
+ database_cleaner (2.0.1)
25
+ database_cleaner-active_record (~> 2.0.0)
26
+ database_cleaner-active_record (2.0.1)
27
+ activerecord (>= 5.a)
28
+ database_cleaner-core (~> 2.0.0)
29
+ database_cleaner-core (2.0.1)
30
+ db-query-matchers (0.10.0)
31
+ activesupport (>= 4.0, < 7)
32
+ rspec (~> 3.0)
33
+ diff-lcs (1.4.4)
34
+ i18n (1.8.10)
35
+ concurrent-ruby (~> 1.0)
36
+ minitest (5.14.4)
37
+ rake (13.0.6)
38
+ rspec (3.10.0)
39
+ rspec-core (~> 3.10.0)
40
+ rspec-expectations (~> 3.10.0)
41
+ rspec-mocks (~> 3.10.0)
42
+ rspec-core (3.10.1)
43
+ rspec-support (~> 3.10.0)
44
+ rspec-expectations (3.10.1)
45
+ diff-lcs (>= 1.2.0, < 2.0)
46
+ rspec-support (~> 3.10.0)
47
+ rspec-mocks (3.10.2)
48
+ diff-lcs (>= 1.2.0, < 2.0)
49
+ rspec-support (~> 3.10.0)
50
+ rspec-support (3.10.2)
51
+ sqlite3 (1.4.2)
52
+ tzinfo (2.0.4)
53
+ concurrent-ruby (~> 1.0)
54
+ zeitwerk (2.4.2)
55
+
56
+ PLATFORMS
57
+ ruby
58
+ x86_64-darwin-19
59
+
60
+ DEPENDENCIES
61
+ activerecord (~> 6.1)
62
+ bundler
63
+ byebug
64
+ database_cleaner
65
+ db-query-matchers
66
+ jit_preloader!
67
+ rake (~> 13.0)
68
+ rspec
69
+ sqlite3
70
+
71
+ BUNDLED WITH
72
+ 2.2.12
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "activerecord", "> 6.0", "< 6.1"
21
+ spec.add_dependency "activerecord", ">= 5.2", "< 7"
22
22
  spec.add_dependency "activesupport"
23
23
 
24
24
  spec.add_development_dependency "bundler"
@@ -49,7 +49,7 @@ module JitPreloader
49
49
  association.target.concat(new_records)
50
50
  association.loaded!
51
51
  else
52
- association.target ||= records.first unless records.empty?
52
+ association.target = records.first unless records.empty?
53
53
  end
54
54
  end
55
55
 
@@ -23,6 +23,15 @@ module JitPreloadExtension
23
23
  return jit_preload_scoped_relations[name] if jit_preload_scoped_relations&.key?(name)
24
24
 
25
25
  records = jit_preloader&.records || [self]
26
+ previous_association_values = {}
27
+
28
+ records.each do |record|
29
+ association = record.association(base_association)
30
+ if association.loaded?
31
+ previous_association_values[record] = association.target
32
+ association.reset
33
+ end
34
+ end
26
35
 
27
36
  preloader_association = ActiveRecord::Associations::Preloader.new.preload(
28
37
  records,
@@ -34,6 +43,10 @@ module JitPreloadExtension
34
43
  record.jit_preload_scoped_relations ||= {}
35
44
  association = record.association(base_association)
36
45
  record.jit_preload_scoped_relations[name] = preloader_association.records_by_owner[record] || []
46
+ association.reset
47
+ if previous_association_values.key?(record)
48
+ association.target = previous_association_values[record]
49
+ end
37
50
  end
38
51
 
39
52
  jit_preload_scoped_relations[name]
@@ -1,3 +1,3 @@
1
1
  module JitPreloader
2
- VERSION = "1.0.3"
2
+ VERSION = "1.0.4"
3
3
  end
@@ -74,6 +74,9 @@ RSpec.describe "ActiveRecord::Base Extensions" do
74
74
 
75
75
  it "doesn't load the value into the association" do
76
76
  contacts = Contact.jit_preload.limit(2).to_a
77
+ expect(contacts.first.association(:addresses)).to_not be_loaded
78
+ expect(contacts.last.association(:addresses)).to_not be_loaded
79
+
77
80
  call(contacts.first)
78
81
 
79
82
  expect(contacts.first.association(:addresses)).to_not be_loaded
@@ -288,6 +288,22 @@ RSpec.describe JitPreloader::Preloader do
288
288
  end
289
289
  end
290
290
 
291
+ context "when a singular association id changes after preload" do
292
+ let!(:contact_book1) { ContactBook.create(name: "The Yellow Pages") }
293
+ let!(:contact_book2) { ContactBook.create(name: "The White Pages") }
294
+ let!(:company1) { Company.create(name: "Company1", contact_book: contact_book1) }
295
+ let!(:company2) { Company.create(name: "Company2", contact_book: contact_book1) }
296
+
297
+ it "allows the association to be reloaded" do
298
+ companies = Company.where(id: [company1.id, company2.id]).jit_preload.all.to_a
299
+ expect(companies.map(&:contact_book)).to match_array [contact_book1, contact_book1]
300
+
301
+ company = companies.each {|c| c.contact_book_id = contact_book2.id }
302
+
303
+ expect(companies.map(&:contact_book)).to match_array [contact_book2, contact_book2]
304
+ end
305
+ end
306
+
291
307
  context "when preloading an aggregate" do
292
308
  let(:addresses_counts) { [3, 0, 2] }
293
309
  let(:phone_number_counts) { [2, 0, 1] }
metadata CHANGED
@@ -1,35 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jit_preloader
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
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-04-13 00:00:00.000000000 Z
11
+ date: 2021-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '6.0'
19
+ version: '5.2'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '6.1'
22
+ version: '7'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - ">"
27
+ - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: '6.0'
29
+ version: '5.2'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '6.1'
32
+ version: '7'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: activesupport
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -151,9 +151,17 @@ executables: []
151
151
  extensions: []
152
152
  extra_rdoc_files: []
153
153
  files:
154
+ - ".github/workflows/CODEOWNERS"
155
+ - ".github/workflows/gem-push.yml"
154
156
  - ".gitignore"
155
157
  - ".rspec"
156
158
  - Gemfile
159
+ - Gemfile.5.2
160
+ - Gemfile.5.2.lock
161
+ - Gemfile.6.0
162
+ - Gemfile.6.0.lock
163
+ - Gemfile.6.1
164
+ - Gemfile.6.1.lock
157
165
  - LICENSE
158
166
  - README.md
159
167
  - Rakefile
@@ -178,7 +186,7 @@ homepage: ''
178
186
  licenses:
179
187
  - MIT
180
188
  metadata: {}
181
- post_install_message:
189
+ post_install_message:
182
190
  rdoc_options: []
183
191
  require_paths:
184
192
  - lib
@@ -193,8 +201,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
193
201
  - !ruby/object:Gem::Version
194
202
  version: '0'
195
203
  requirements: []
196
- rubygems_version: 3.2.3
197
- signing_key:
204
+ rubygems_version: 3.1.6
205
+ signing_key:
198
206
  specification_version: 4
199
207
  summary: Tool to understand N+1 queries and to remove them
200
208
  test_files: