ar_lazy_preload 1.1.1 → 2.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 +4 -4
- data/README.md +6 -0
- data/lib/ar_lazy_preload/active_record/base.rb +9 -2
- data/lib/ar_lazy_preload/railtie.rb +1 -23
- data/lib/ar_lazy_preload/version.rb +1 -1
- data/lib/ar_lazy_preload.rb +25 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f8b5858ee6bbfd4ba3db6c61f5577ef7651c06b63bb4c38ddc5dad7a61dba2d
|
4
|
+
data.tar.gz: 1087cc1b4e487d6a6a404e3def90ee9dc3baf9b1c143b5a58176dbd27d206f40
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd0d2df79afe940662c1cab747c0fa1e8d2dab46eaba585663a2441c0f1058bd56d355e16d1feba4a46af52fe81167133c0e1e42dc3e31212b702310e57d2f92
|
7
|
+
data.tar.gz: 2398c417a95f0c1472b677647e74f5bbdd02c5c426f7d41b583d33557122642dbd0925feeb7ca62bbb36ad5ba5c934280e7e10d3898a3b4e9f8c4ac5c8e02c32
|
data/README.md
CHANGED
@@ -7,6 +7,12 @@
|
|
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
|
|
10
|
+
Used in production by:
|
11
|
+
|
12
|
+
- [Fund that flip](https://evilmartians.com/chronicles/big-refactoring-fix-that-app-for-fund-that-flip)
|
13
|
+
- Toptal
|
14
|
+
- _Want to be here? Let me know_ 🙂
|
15
|
+
|
10
16
|
## Why should I use it?
|
11
17
|
|
12
18
|
Lazy loading is super helpful when the list of associations to load is determined dynamically. For instance, in GraphQL this list comes from the API client, and you'll have to inspect the selection set to find out what associations are going to be used.
|
@@ -6,7 +6,10 @@ module ArLazyPreload
|
|
6
6
|
def self.included(base)
|
7
7
|
base.class.delegate :lazy_preload, to: :all
|
8
8
|
base.class.delegate :preload_associations_lazily, to: :all
|
9
|
+
|
9
10
|
base.after_create { try_setup_auto_preload_context }
|
11
|
+
|
12
|
+
base.extend(ClassMethods)
|
10
13
|
end
|
11
14
|
|
12
15
|
attr_accessor :lazy_preload_context
|
@@ -23,10 +26,14 @@ module ArLazyPreload
|
|
23
26
|
self
|
24
27
|
end
|
25
28
|
|
26
|
-
private
|
27
|
-
|
28
29
|
def try_setup_auto_preload_context
|
29
30
|
ArLazyPreload::Context.register(records: [self]) if ArLazyPreload.config.auto_preload?
|
30
31
|
end
|
32
|
+
|
33
|
+
module ClassMethods
|
34
|
+
def find_by(*args)
|
35
|
+
super(*args).tap { |object| object&.try_setup_auto_preload_context }
|
36
|
+
end
|
37
|
+
end
|
31
38
|
end
|
32
39
|
end
|
@@ -1,32 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "ar_lazy_preload/active_record/base"
|
4
|
-
require "ar_lazy_preload/active_record/relation"
|
5
|
-
require "ar_lazy_preload/active_record/association"
|
6
|
-
require "ar_lazy_preload/active_record/collection_association"
|
7
|
-
require "ar_lazy_preload/active_record/merger"
|
8
|
-
require "ar_lazy_preload/active_record/association_relation"
|
9
|
-
require "ar_lazy_preload/active_record/collection_proxy"
|
10
|
-
|
11
3
|
module ArLazyPreload
|
12
4
|
class Railtie < Rails::Railtie
|
13
5
|
config.to_prepare do |_app|
|
14
6
|
ActiveSupport.on_load(:active_record) do
|
15
|
-
|
16
|
-
|
17
|
-
ActiveRecord::Relation.prepend(Relation)
|
18
|
-
ActiveRecord::AssociationRelation.prepend(AssociationRelation)
|
19
|
-
ActiveRecord::Relation::Merger.prepend(Merger)
|
20
|
-
|
21
|
-
[
|
22
|
-
ActiveRecord::Associations::CollectionAssociation,
|
23
|
-
ActiveRecord::Associations::Association
|
24
|
-
].each { |klass| klass.prepend(Association) }
|
25
|
-
|
26
|
-
ActiveRecord::Associations::CollectionAssociation.prepend(CollectionAssociation)
|
27
|
-
ActiveRecord::Associations::CollectionProxy.prepend(CollectionProxy)
|
28
|
-
|
29
|
-
ArLazyPreload::Preloader.patch_for_rails_7! if ActiveRecord::VERSION::MAJOR >= 7
|
7
|
+
ArLazyPreload.install_hooks
|
30
8
|
end
|
31
9
|
end
|
32
10
|
end
|
data/lib/ar_lazy_preload.rb
CHANGED
@@ -1,12 +1,36 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "ar_lazy_preload/configuration"
|
4
|
-
require "ar_lazy_preload/railtie"
|
4
|
+
require "ar_lazy_preload/railtie" if defined?(::Rails)
|
5
|
+
|
6
|
+
require "ar_lazy_preload/active_record/base"
|
7
|
+
require "ar_lazy_preload/active_record/relation"
|
8
|
+
require "ar_lazy_preload/active_record/association"
|
9
|
+
require "ar_lazy_preload/active_record/collection_association"
|
10
|
+
require "ar_lazy_preload/active_record/merger"
|
11
|
+
require "ar_lazy_preload/active_record/association_relation"
|
12
|
+
require "ar_lazy_preload/active_record/collection_proxy"
|
5
13
|
|
6
14
|
module ArLazyPreload
|
7
15
|
class << self
|
8
16
|
def config
|
9
17
|
@config ||= Configuration.new
|
10
18
|
end
|
19
|
+
|
20
|
+
def install_hooks
|
21
|
+
ActiveRecord::Base.include(Base)
|
22
|
+
|
23
|
+
ActiveRecord::Relation.prepend(Relation)
|
24
|
+
ActiveRecord::AssociationRelation.prepend(AssociationRelation)
|
25
|
+
ActiveRecord::Relation::Merger.prepend(Merger)
|
26
|
+
|
27
|
+
ActiveRecord::Associations::CollectionAssociation.prepend(Association)
|
28
|
+
ActiveRecord::Associations::Association.prepend(Association)
|
29
|
+
|
30
|
+
ActiveRecord::Associations::CollectionAssociation.prepend(CollectionAssociation)
|
31
|
+
ActiveRecord::Associations::CollectionProxy.prepend(CollectionProxy)
|
32
|
+
|
33
|
+
ArLazyPreload::Preloader.patch_for_rails_7! if ActiveRecord::VERSION::MAJOR >= 7
|
34
|
+
end
|
11
35
|
end
|
12
36
|
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:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- DmitryTsepelev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-03-10 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: '
|
20
|
-
type: :
|
19
|
+
version: '6.0'
|
20
|
+
type: :development
|
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: '
|
26
|
+
version: '6.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -220,7 +220,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
220
220
|
requirements:
|
221
221
|
- - ">="
|
222
222
|
- !ruby/object:Gem::Version
|
223
|
-
version: '2.
|
223
|
+
version: '2.7'
|
224
224
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
225
225
|
requirements:
|
226
226
|
- - ">="
|