ar_lazy_preload 0.7.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 780b04da1bdc2de0822bcf78d9ac51d7e24f5bf66aee70d42e81a0a0cb662a21
4
- data.tar.gz: bceb49a3525fcfcac85d8662485992bc81e37015a9100a4332f3aaae1c0bd59e
3
+ metadata.gz: 853f4f5f10ba5f9aa5e6530eb767f9d4063d62745b2b332776c7ebb44c753700
4
+ data.tar.gz: ff2f6a626e8e944734dcab46eef9677bda77582027f1e687b27b616a5cdac0cb
5
5
  SHA512:
6
- metadata.gz: d32ee8fe923b29451f032ebb050168d6eaec8d5aec0b3136917a8196284198323ed804061bf64c7b36e104b95a43ced12372baa39a79976a1f69ae22a44c190c
7
- data.tar.gz: d104a956772f064cb255db1f6743edd312da87da0526d2eff669976ce6f8537fb78a49cb302fa818942a4bb2bf1f0f0ae4226053c696e4575981aef774c356a9
6
+ metadata.gz: f873a03ba3abc319042f601e512b48b64d638f3b6358e722768e92745992c654f4aef229e792690c0c250563c9f28ae2d69fd77931c9af27db9a09f719f6341f
7
+ data.tar.gz: 521c1bf8d19bc8bc2c5e71c8fd2918ac400102368016a9d6448b19426bcefc569b51fda0e13b205d86a872553f08a619a436fb3c7821bb4b866056c771065121
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
- # ArLazyPreload [![Cult Of Martians](http://cultofmartians.com/assets/badges/badge.svg)](https://cultofmartians.com/tasks/activerecord-lazy-preload.html) [![Gem Version](https://badge.fury.io/rb/ar_lazy_preload.svg)](https://rubygems.org/gems/ar_lazy_preload) [![Build Status](https://travis-ci.org/DmitryTsepelev/ar_lazy_preload.svg?branch=master)](https://travis-ci.org/DmitryTsepelev/ar_lazy_preload) [![Maintainability](https://api.codeclimate.com/v1/badges/00d04595661820dfba80/maintainability)](https://codeclimate.com/github/DmitryTsepelev/ar_lazy_preload/maintainability) [![Coverage Status](https://coveralls.io/repos/github/DmitryTsepelev/ar_lazy_preload/badge.svg?branch=master)](https://coveralls.io/github/DmitryTsepelev/ar_lazy_preload?branch=master)
1
+ # ArLazyPreload [![Cult Of Martians](http://cultofmartians.com/assets/badges/badge.svg)](https://cultofmartians.com/tasks/activerecord-lazy-preload.html) [![Gem Version](https://badge.fury.io/rb/ar_lazy_preload.svg)](https://rubygems.org/gems/ar_lazy_preload) [![Build Status](https://github.com/DmitryTsepelev/ar_lazy_preload/actions/workflows/rspec.yml/badge.svg)](https://github.com/DmitryTsepelev/ar_lazy_preload/actions/workflows/rspec.yml) [![Maintainability](https://api.codeclimate.com/v1/badges/00d04595661820dfba80/maintainability)](https://codeclimate.com/github/DmitryTsepelev/ar_lazy_preload/maintainability) [![Coverage Status](https://coveralls.io/repos/github/DmitryTsepelev/ar_lazy_preload/badge.svg?branch=master)](https://coveralls.io/github/DmitryTsepelev/ar_lazy_preload?branch=master)
2
2
 
3
3
  **ArLazyPreload** is a gem that brings association lazy load functionality to your Rails applications. There is a number of built-in methods to solve [N+1 problem](https://guides.rubyonrails.org/active_record_querying.html#eager-loading-associations), but sometimes a list of associations to preload is not obvious–this is when you can get most of this gem.
4
4
 
5
5
  - **Simple**. The only thing you need to change is to use `#lazy_preload` instead of `#includes`, `#eager_load` or `#preload`
6
- - **Fast**. Take a look at [benchmarks](https://travis-ci.org/DmitryTsepelev/ar_lazy_preload) (`TASK=bench` and `TASK=memory`)
6
+ - **Fast**. Take a look at [performance benchmark](https://github.com/DmitryTsepelev/ar_lazy_preload/actions/workflows/bench.yml) and [memory benchmark](https://github.com/DmitryTsepelev/ar_lazy_preload/actions/workflows/memory.yml)
7
7
  - **Perfect fit for GraphQL**. Define a list of associations to load at the top-level resolver and let the gem do its job
8
8
  - **Auto-preload support**. If you don't want to specify the association list–set `ArLazyPreload.config.auto_preload` to `true`
9
9
 
@@ -12,11 +12,9 @@ module ArLazyPreload
12
12
  def preload_associations(records)
13
13
  preload = preload_values
14
14
  preload += includes_values unless eager_loading?
15
- preloader = nil
15
+
16
16
  preload.each do |associations|
17
- preloader ||= build_preloader
18
- preloader_associations = preloader.preload records, associations
19
- preloader_associations.each do |preloader_association|
17
+ ArLazyPreload::Preloader.new(records, associations).preload.each do |preloader_association|
20
18
  handle_preloaded_records(preloader_association.preloaded_records)
21
19
  end
22
20
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "set"
4
4
  require "ar_lazy_preload/associated_context_builder"
5
+ require "ar_lazy_preload/preloader"
5
6
 
6
7
  module ArLazyPreload
7
8
  module Contexts
@@ -63,7 +64,7 @@ module ArLazyPreload
63
64
  # help of the TemporaryPreloadConfig
64
65
  def preload_records(association_name, records)
65
66
  TemporaryPreloadConfig.within_context do
66
- preloader.preload(records, association_name)
67
+ ArLazyPreload::Preloader.new(records, [association_name]).preload
67
68
  end
68
69
  end
69
70
 
@@ -75,10 +76,6 @@ module ArLazyPreload
75
76
  @loaded_association_names ||= Set.new
76
77
  end
77
78
 
78
- def preloader
79
- @preloader ||= ActiveRecord::Associations::Preloader.new
80
- end
81
-
82
79
  def preloadable_record?(association_name, record)
83
80
  preloadable_reflections_cache.dig(record.class, association_name)
84
81
  end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ArLazyPreload
4
+ class Preloader
5
+ def initialize(records, associations)
6
+ @records = records
7
+ @associations = associations
8
+ end
9
+
10
+ class << self
11
+ def patch_for_rails_7!
12
+ define_method(:preload) do
13
+ ActiveRecord::Associations::Preloader.new(
14
+ records: @records, associations: @associations
15
+ ).call
16
+ end
17
+ end
18
+ end
19
+
20
+ def preload
21
+ ActiveRecord::Associations::Preloader.new.preload(@records, @associations)
22
+ end
23
+ end
24
+ end
@@ -25,6 +25,8 @@ module ArLazyPreload
25
25
 
26
26
  ActiveRecord::Associations::CollectionAssociation.prepend(CollectionAssociation)
27
27
  ActiveRecord::Associations::CollectionProxy.prepend(CollectionProxy)
28
+
29
+ ArLazyPreload::Preloader.patch_for_rails_7! if ActiveRecord::VERSION::MAJOR >= 7
28
30
  end
29
31
  end
30
32
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ArLazyPreload
4
- VERSION = "0.7.0"
4
+ VERSION = "1.0.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ar_lazy_preload
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - DmitryTsepelev
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-21 00:00:00.000000000 Z
11
+ date: 2021-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '5.0'
19
+ version: '5.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '5.0'
26
+ version: '5.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -205,13 +205,14 @@ files:
205
205
  - lib/ar_lazy_preload/contexts/lazy_preload_context.rb
206
206
  - lib/ar_lazy_preload/contexts/temporary_preload_config.rb
207
207
  - lib/ar_lazy_preload/preloaded_records_converter.rb
208
+ - lib/ar_lazy_preload/preloader.rb
208
209
  - lib/ar_lazy_preload/railtie.rb
209
210
  - lib/ar_lazy_preload/version.rb
210
211
  homepage: https://github.com/DmitryTsepelev/ar_lazy_preload
211
212
  licenses:
212
213
  - MIT
213
214
  metadata: {}
214
- post_install_message:
215
+ post_install_message:
215
216
  rdoc_options: []
216
217
  require_paths:
217
218
  - lib
@@ -219,15 +220,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
219
220
  requirements:
220
221
  - - ">="
221
222
  - !ruby/object:Gem::Version
222
- version: '2.3'
223
+ version: '2.6'
223
224
  required_rubygems_version: !ruby/object:Gem::Requirement
224
225
  requirements:
225
226
  - - ">="
226
227
  - !ruby/object:Gem::Version
227
228
  version: '0'
228
229
  requirements: []
229
- rubygems_version: 3.1.1
230
- signing_key:
230
+ rubygems_version: 3.1.4
231
+ signing_key:
231
232
  specification_version: 4
232
233
  summary: lazy_preload implementation for ActiveRecord models
233
234
  test_files: []