ar_lazy_preload 2.1.1 → 2.1.2

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: 927bf2110e3c5733916353191cbc1c1b9543dab216b6aef4b120cd6383822796
4
- data.tar.gz: 24e78260d612a9d212c4b53937abff9cf6f68e32aa5728c60b4d686ea49efcf8
3
+ metadata.gz: 21e63192d8ab41a89c7fa7fe49300123e7f8759d7e3270fdf4d821bc9865db8b
4
+ data.tar.gz: 28485e31dd75c9c93949ff9cc7a5a284857d347892a58a050cf754f50204beff
5
5
  SHA512:
6
- metadata.gz: 88ca2ecb46671b3ec6f671d06c540a24bbcade260d68309993d2049e76730926b173074b3255cafc51e2d4e8636f5b7a3fbf4b17c1c838b5a4935c0545ffbf81
7
- data.tar.gz: 5266eb7b7901631633a4c8ee554935c29757c60955f2749910ffd2e3688bc66a30edd330e9703c7775020868a0836f8d181cd6ed1f357719098f04a4791a437c
6
+ metadata.gz: 34932cd853c5344aa865da00c1210a0680e0b18e3ac4994a9908d16683d97905deaaf56b4cd2963ef01c20352df63f80fd4021d97a1831a4691129c5382c4a35
7
+ data.tar.gz: d40a3cf3c8ef27508e385649a4373fe84fca14796c9cd44fdb7b6df55123f9b09f9bf00d9fcfb255ba9b3c8844633e05968a50297cc6867f1ce21664e4a45944
data/README.md CHANGED
@@ -13,7 +13,10 @@ Used in production by:
13
13
  - Toptal
14
14
  - _Want to be here? Let me know_ 🙂
15
15
 
16
- You can support my open–source work [here](https://boosty.to/dmitry_tsepelev).
16
+ ## Professional Support
17
+
18
+ Dealing with performance issues in your Rails app beyond N+1 queries?
19
+ I'm available for consulting — [get in touch](https://dmitrytsepelev.dev/consulting).
17
20
 
18
21
  ## Why should I use it?
19
22
 
@@ -64,6 +67,10 @@ posts = User.preload_associations_lazily.flat_map(&:posts)
64
67
  # => SELECT * FROM posts WHERE user_id in (...)
65
68
  ```
66
69
 
70
+ ## Companion gem for non-association N+1s
71
+
72
+ [`N1Loader`](https://github.com/djezzzl/n1_loader) complements ArLazyPreload for batched lazy loading in places where regular ActiveRecord associations are not available (for example, computed values, custom loaders, service/API calls, and GraphQL fields). ArLazyPreload can stay focused on association loading while N1Loader handles the remaining N+1-prone derived data.
73
+
67
74
  ## Gotchas
68
75
 
69
76
  1. Lazy preloading [does not work](https://github.com/DmitryTsepelev/ar_lazy_preload/pull/40/files) for ActiveRecord < 6 when `.includes` is called earlier:
@@ -44,7 +44,7 @@ module ArLazyPreload
44
44
  #
45
45
  # Same effect can be achieved by User.lazy_preload(posts: :comments)
46
46
  def preload_associations_lazily
47
- spawn.tap { |relation| relation.preloads_associations_lazily = true }
47
+ tap { |relation| relation.preloads_associations_lazily = true }
48
48
  end
49
49
 
50
50
  # Specify relationships to be loaded lazily when association is loaded for the first time. For
@@ -23,7 +23,7 @@ module ArLazyPreload
23
23
 
24
24
  # Takes all the associated records for the records, attached to the :parent_context and creates
25
25
  # a preloading context for them
26
- # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
26
+ # rubocop:disable Metrics/MethodLength
27
27
  def perform
28
28
  associated_records = parent_context.records.flat_map do |record|
29
29
  next if record.nil?
@@ -32,7 +32,7 @@ module ArLazyPreload
32
32
  next if reflection.nil?
33
33
 
34
34
  record_association = record.association(association_name)
35
- reflection.collection? ? record_association.target : record_association.reader
35
+ record_association.target
36
36
  end
37
37
 
38
38
  Context.register(
@@ -41,7 +41,7 @@ module ArLazyPreload
41
41
  auto_preload: parent_context.auto_preload?
42
42
  )
43
43
  end
44
- # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
44
+ # rubocop:enable Metrics/MethodLength
45
45
 
46
46
  private
47
47
 
@@ -90,7 +90,7 @@ module ArLazyPreload
90
90
  def collect_intermediate_records(klass_records, reflection)
91
91
  klass_records.flat_map do |record|
92
92
  record_association = record.association(reflection.name)
93
- reflection.collection? ? record_association.target : record_association.reader
93
+ record_association.target
94
94
  end.compact
95
95
  end
96
96
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ArLazyPreload
4
- VERSION = "2.1.1"
4
+ VERSION = "2.1.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ar_lazy_preload
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - DmitryTsepelev