ar_lazy_preload 0.2.7 → 0.3.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: 0e0790a19fd33c7b141ba62725951c084f84cd0d1e8678e807081dac6d1b9c4c
4
- data.tar.gz: 714b3e6785f5ad4dd7278be3549638ec8ab2447cad82cc3f9a5cd53694d23006
3
+ metadata.gz: 18865f27f303c041869d4cbeb759d90adde8f2255b970d0752d789b0604f3846
4
+ data.tar.gz: f6818b6e38baf72a2bd8881c6727a70fc01a4c90916ed888cf0e51c837858851
5
5
  SHA512:
6
- metadata.gz: e3f9bfdd8dec8fb021f96ad79b686248e15dc30e23585a3c7e386033c72ec8864d75de8c8a21c4c0ef00e57e63e61c7bd147a6554d5e634f6282959f11bade82
7
- data.tar.gz: d9537e25cc267fdc4278f2ae467945482abb78e2716d823c915ce2c5d82c7190ed9713ab8ad2cf5f219eceb4b72954c9eb25854b5b593e3c9726d0dcef50b8cb
6
+ metadata.gz: 81e6e8d0dc2ced79052f0b05018a87353abbf416ee234ff6f00c98fa22912a08b4161bece20f78187d25c9221a13ba2f4bea7450916f4f32900e0c60dac99d6e
7
+ data.tar.gz: 5f970163332f177b5dbfbbe000fbbca4174bfe822d512ceb3bfa2263a769dfd438d39d7faf2cc516f7d05a7cfb1bd5b2bf1377ec7592312b9a6f7f75e92602fa
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ArLazyPreload
4
+ # ActiveRecord::CollectionAssociation patch with a hook for lazy preloading
5
+ module CollectionAssociation
6
+ # rubocop:disable Metrics/AbcSize
7
+ def ids_reader
8
+ return super if owner.lazy_preload_context.blank?
9
+
10
+ primary_key = reflection.association_primary_key.to_sym
11
+ if loaded?
12
+ target.map(&primary_key)
13
+ elsif !target.empty?
14
+ load_target.map(&primary_key)
15
+ else
16
+ @association_ids ||= reader.map(&primary_key)
17
+ end
18
+ end
19
+ # rubocop:enable Metrics/AbcSize
20
+ end
21
+ end
@@ -15,6 +15,7 @@ module ArLazyPreload
15
15
  def initialize(records:)
16
16
  @records = records.dup
17
17
  @records.compact!
18
+ @records.uniq!
18
19
  @records.each { |record| record.lazy_preload_context = self }
19
20
  end
20
21
 
@@ -3,6 +3,7 @@
3
3
  require "ar_lazy_preload/active_record/base"
4
4
  require "ar_lazy_preload/active_record/relation"
5
5
  require "ar_lazy_preload/active_record/association"
6
+ require "ar_lazy_preload/active_record/collection_association"
6
7
  require "ar_lazy_preload/active_record/merger"
7
8
  require "ar_lazy_preload/active_record/association_relation"
8
9
  require "ar_lazy_preload/active_record/collection_proxy"
@@ -22,6 +23,7 @@ module ArLazyPreload
22
23
  ActiveRecord::Associations::Association
23
24
  ].each { |klass| klass.prepend(Association) }
24
25
 
26
+ ActiveRecord::Associations::CollectionAssociation.prepend(CollectionAssociation)
25
27
  ActiveRecord::Associations::CollectionProxy.prepend(CollectionProxy)
26
28
  end
27
29
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ArLazyPreload
4
- VERSION = "0.2.7"
4
+ VERSION = "0.3.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.2.7
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - DmitryTsepelev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-05 00:00:00.000000000 Z
11
+ date: 2020-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -164,6 +164,7 @@ files:
164
164
  - lib/ar_lazy_preload/active_record/association.rb
165
165
  - lib/ar_lazy_preload/active_record/association_relation.rb
166
166
  - lib/ar_lazy_preload/active_record/base.rb
167
+ - lib/ar_lazy_preload/active_record/collection_association.rb
167
168
  - lib/ar_lazy_preload/active_record/collection_proxy.rb
168
169
  - lib/ar_lazy_preload/active_record/merger.rb
169
170
  - lib/ar_lazy_preload/active_record/relation.rb