n1_loader 1.4.4 → 1.5.0

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: 3e0025899b1fbd0329159dcd2e1ddf1d28318fe76354fd2e1378b803e49a9d96
4
- data.tar.gz: 2f0f222cd9298bb56e2c3a9ae8c1f6559c7ec2bec3653c5a9a2c7c172b49b7fd
3
+ metadata.gz: bf26363e90cf5f0b6759776698445183f4abe8442bf366e7109e1cada18b1eaa
4
+ data.tar.gz: e082a72dc1f910262fbc73040b484ae28e437beee866ca42277a7556d989072a
5
5
  SHA512:
6
- metadata.gz: 48a55dd01386410a58a5fbf8ea9d556ac6fa2db33411a469b2c9f3fc99b9ccec2ad36eb482e0adba39a84af4ffd4adba6a51a8db23eba7869c03aca51add1d39
7
- data.tar.gz: b4c275204251a8e6908e34af67beacd6bbc05a1fcd1168350ab538ecf48362c840c671d1223dfd3659b2fe87f1428ee0e012144c3c52fa11451a595a0b5a11d9
6
+ metadata.gz: 52993103afc0075d9d71088e6d7e60925ea1740176ee31829acb5d42009a38955b25d8e9124a17fff981b4735f443c04d3532cbea3186850bffc2908f0e40522
7
+ data.tar.gz: fdcc21a626ff199ccf4a9af7bd860516745693614404c44159414b27601750ea476de8eae593f7bade3782425b638f784db096e6dcdaafa58c71382f3a08b979
data/.circleci/config.yml CHANGED
@@ -106,7 +106,8 @@ workflows:
106
106
  ]
107
107
  activerecord-gemfile: [
108
108
  "ar_5_latest",
109
- "ar_6_latest"
109
+ "ar_6_latest",
110
+ "ar_7_latest"
110
111
  ]
111
112
  ar_lazy_preload-gemfile: [
112
113
  "ar_lazy_preload_0.6.1",
@@ -115,21 +116,40 @@ workflows:
115
116
  exclude:
116
117
  # Ruby 2.5 and AR Lazy Preload 1+
117
118
  - ruby-version: "2.5"
118
- activerecord-gemfile: "ar_5_latest"
119
119
  ar_lazy_preload-gemfile: "ar_lazy_preload_master"
120
+ activerecord-gemfile: "ar_5_latest"
120
121
 
121
122
  - ruby-version: "2.5"
123
+ ar_lazy_preload-gemfile: "ar_lazy_preload_master"
122
124
  activerecord-gemfile: "ar_6_latest"
125
+
126
+ - ruby-version: "2.5"
123
127
  ar_lazy_preload-gemfile: "ar_lazy_preload_master"
128
+ activerecord-gemfile: "ar_7_latest"
124
129
 
125
130
  # AR 5 and ruby 3+
126
131
  - ruby-version: "latest"
127
132
  activerecord-gemfile: "ar_5_latest"
128
133
  ar_lazy_preload-gemfile: "ar_lazy_preload_0.6.1"
134
+
129
135
  - ruby-version: "latest"
130
136
  activerecord-gemfile: "ar_5_latest"
131
137
  ar_lazy_preload-gemfile: "ar_lazy_preload_master"
132
138
 
139
+ # AR 7 and ar_lazy_preload < 1
140
+ - ruby-version: "2.5"
141
+ activerecord-gemfile: "ar_7_latest"
142
+ ar_lazy_preload-gemfile: "ar_lazy_preload_0.6.1"
143
+
144
+ - ruby-version: "2.7"
145
+ activerecord-gemfile: "ar_7_latest"
146
+ ar_lazy_preload-gemfile: "ar_lazy_preload_0.6.1"
147
+
148
+ - ruby-version: "latest"
149
+ activerecord-gemfile: "ar_7_latest"
150
+ ar_lazy_preload-gemfile: "ar_lazy_preload_0.6.1"
151
+
152
+
133
153
  name: ruby-<< matrix.ruby-version >>-<< matrix.activerecord-gemfile >>-<< matrix.ar_lazy_preload-gemfile >>
134
154
  - rubocop:
135
155
  requires:
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## [1.5.0] - 2022/05/01
2
+
3
+ - Add support of Rails 7
4
+
1
5
  ## [1.4.4] - 2022/04/29
2
6
 
3
7
  - Inject `N1Loader::Loadable` to `ActiveRecord::Base` automatically
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  [![CircleCI][1]][2]
4
4
  [![Gem Version][3]][4]
5
5
 
6
- N1Loader is designed to provide a way for avoiding [N+1 issues][7] of any kind.
6
+ N1Loader is designed to provide a simple way for avoiding [N+1 issues][7] of any kind.
7
7
  For example, it can help with resolving N+1 for:
8
8
  - database querying (most common case)
9
9
  - 3rd party service calls
@@ -23,7 +23,7 @@ gem 'n1_loader', require: 'n1_loader/ar_lazy_preload'
23
23
 
24
24
  ## Enhance [ActiveRecord][5]
25
25
 
26
- Are you working with well-known Rails application? Try it out how well N1Loader fulfills missing gaps!
26
+ Are you working with well-known Rails application? Try it out and see how well N1Loader fulfills missing gaps when you can't define ActiveRecord associations!
27
27
 
28
28
  ```ruby
29
29
  gem 'n1_loader', require: 'n1_loader/active_record'
@@ -173,4 +173,4 @@ Copyright (c) Evgeniy Demin. See [LICENSE.txt](LICENSE.txt) for further details.
173
173
  [5]: https://github.com/rails/rails/tree/main/activerecord
174
174
  [6]: https://github.com/DmitryTsepelev/ar_lazy_preload
175
175
  [7]: https://stackoverflow.com/questions/97197/what-is-the-n1-selects-problem-in-orm-object-relational-mapping
176
- [8]: https://github.com/djezzzl/n1_loader
176
+ [8]: https://github.com/djezzzl/n1_loader
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ gem "activerecord", "~> 7"
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module N1Loader
4
+ module ActiveRecord
5
+ module Associations
6
+ module Preloader # :nodoc:
7
+ N1LoaderReflection = Struct.new(:key, :loader) do
8
+ def options
9
+ {}
10
+ end
11
+ end
12
+
13
+ def preloaders_for_reflection(reflection, records)
14
+ return super unless reflection.is_a?(N1LoaderReflection)
15
+
16
+ N1Loader::Preloader.new(records).preload(reflection.key)
17
+ end
18
+
19
+ def grouped_records # rubocop:disable Metrics/PerceivedComplexity, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/AbcSize
20
+ n1_load_records, records = source_records.partition do |record|
21
+ record.class.respond_to?(:n1_loader_defined?) && record.class.n1_loader_defined?(association)
22
+ end
23
+
24
+ h = n1_load_records.group_by do |record|
25
+ N1LoaderReflection.new(association, record.class.n1_loader(association))
26
+ end
27
+
28
+ polymorphic_parent = !root? && parent.polymorphic?
29
+ records.each do |record|
30
+ reflection = record.class._reflect_on_association(association)
31
+ next if polymorphic_parent && !reflection || !record.association(association).klass
32
+
33
+ (h[reflection] ||= []) << record
34
+ end
35
+ h
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -5,3 +5,11 @@ N1Loader::LoaderCollection.define_method :preloaded_records do
5
5
 
6
6
  with.preloaded_records
7
7
  end
8
+
9
+ N1Loader::LoaderCollection.define_method :runnable_loaders do
10
+ [self]
11
+ end
12
+
13
+ N1Loader::LoaderCollection.define_method :run? do
14
+ true
15
+ end
@@ -21,10 +21,14 @@ ActiveSupport.on_load(:active_record) do
21
21
  case ActiveRecord::VERSION::MAJOR
22
22
  when 6
23
23
  require_relative "active_record/associations_preloader_v6"
24
- else
24
+ ActiveRecord::Associations::Preloader.prepend(N1Loader::ActiveRecord::Associations::Preloader)
25
+ when 5
25
26
  require_relative "active_record/associations_preloader_v5"
27
+ ActiveRecord::Associations::Preloader.prepend(N1Loader::ActiveRecord::Associations::Preloader)
28
+ else
29
+ require_relative "active_record/associations_preloader_v7"
30
+ ActiveRecord::Associations::Preloader::Branch.prepend(N1Loader::ActiveRecord::Associations::Preloader)
26
31
  end
27
32
 
28
- ActiveRecord::Associations::Preloader.prepend(N1Loader::ActiveRecord::Associations::Preloader)
29
33
  ActiveRecord::Base.include(N1Loader::ActiveRecord::Base)
30
34
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module N1Loader
4
- VERSION = "1.4.4"
4
+ VERSION = "1.5.0"
5
5
  end
data/n1_loader.gemspec CHANGED
@@ -22,9 +22,9 @@ Gem::Specification.new do |spec|
22
22
  end
23
23
  spec.require_paths = ["lib"]
24
24
 
25
- spec.add_development_dependency "activerecord", ">= 5", "< 7"
25
+ spec.add_development_dependency "activerecord", ">= 5"
26
26
  spec.add_development_dependency "ar_lazy_preload", ">= 0.6"
27
- spec.add_development_dependency "db-query-matchers", "~> 0.10"
27
+ spec.add_development_dependency "db-query-matchers", "~> 0.11"
28
28
  spec.add_development_dependency "graphql", "~> 2.0"
29
29
  spec.add_development_dependency "rails", ">= 5"
30
30
  spec.add_development_dependency "rspec", "~> 3.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: n1_loader
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.4
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evgeniy Demin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-29 00:00:00.000000000 Z
11
+ date: 2022-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -17,9 +17,6 @@ dependencies:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '5'
20
- - - "<"
21
- - !ruby/object:Gem::Version
22
- version: '7'
23
20
  type: :development
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
@@ -27,9 +24,6 @@ dependencies:
27
24
  - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '5'
30
- - - "<"
31
- - !ruby/object:Gem::Version
32
- version: '7'
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: ar_lazy_preload
35
29
  requirement: !ruby/object:Gem::Requirement
@@ -50,14 +44,14 @@ dependencies:
50
44
  requirements:
51
45
  - - "~>"
52
46
  - !ruby/object:Gem::Version
53
- version: '0.10'
47
+ version: '0.11'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
51
  requirements:
58
52
  - - "~>"
59
53
  - !ruby/object:Gem::Version
60
- version: '0.10'
54
+ version: '0.11'
61
55
  - !ruby/object:Gem::Dependency
62
56
  name: graphql
63
57
  requirement: !ruby/object:Gem::Requirement
@@ -161,6 +155,7 @@ files:
161
155
  - Rakefile
162
156
  - activerecord-gemfiles/ar_5_latest.gemfile
163
157
  - activerecord-gemfiles/ar_6_latest.gemfile
158
+ - activerecord-gemfiles/ar_7_latest.gemfile
164
159
  - ar_lazy_preload-gemfiles/ar_lazy_preload_0.6.1.gemfile
165
160
  - ar_lazy_preload-gemfiles/ar_lazy_preload_master.gemfile
166
161
  - bin/console
@@ -182,6 +177,7 @@ files:
182
177
  - lib/n1_loader/active_record.rb
183
178
  - lib/n1_loader/active_record/associations_preloader_v5.rb
184
179
  - lib/n1_loader/active_record/associations_preloader_v6.rb
180
+ - lib/n1_loader/active_record/associations_preloader_v7.rb
185
181
  - lib/n1_loader/active_record/base.rb
186
182
  - lib/n1_loader/active_record/loader.rb
187
183
  - lib/n1_loader/active_record/loader_collection.rb