ams_lazy_relationships 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -4
- data/CHANGELOG.md +18 -1
- data/Gemfile.lock +7 -3
- data/README.md +30 -0
- data/RELEASE.md +12 -0
- data/Rakefile +1 -1
- data/ams_lazy_relationships.gemspec +3 -1
- data/lib/ams_lazy_relationships/loaders/association.rb +1 -1
- data/lib/ams_lazy_relationships/loaders/direct.rb +1 -1
- data/lib/ams_lazy_relationships/loaders/simple_belongs_to.rb +1 -1
- data/lib/ams_lazy_relationships/loaders/simple_has_many.rb +1 -1
- data/lib/ams_lazy_relationships/version.rb +1 -1
- metadata +19 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dbafe51edd7b544ae1aa9f0338cb50d22a54d9f1
|
4
|
+
data.tar.gz: d60d837607389b59a521deb7a3486d3ec9c951b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bee54b4366b2ddb41a43c4ca79db09162d7a2910e2570e046d57c79fb5bfee4031d2c2674af2dd04e5c276c93b0d8805a8a7871239bcbb60386310ac7e0cbc3b
|
7
|
+
data.tar.gz: 1de8a52d3743bcbeb955bbda27f8974c9d34dd6b3a3c1350c75fa2b646b9af955e53276cedd6b52b052516e781fe6bfc79f8c1f29ce20fe7cb6f612301121525
|
data/.travis.yml
CHANGED
@@ -11,15 +11,11 @@ gemfile:
|
|
11
11
|
cache: bundler
|
12
12
|
rvm:
|
13
13
|
- 2.3.4
|
14
|
-
before_install:
|
15
|
-
- gem install bundler:1.17 undercover --no-doc
|
16
14
|
before_script:
|
17
15
|
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
18
16
|
- chmod +x ./cc-test-reporter
|
19
17
|
- ./cc-test-reporter before-build
|
20
18
|
script:
|
21
19
|
- bundle exec rake
|
22
|
-
- git pull origin master:master
|
23
|
-
- undercover --compare master
|
24
20
|
after_script:
|
25
21
|
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,22 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## [v0.1.4](https://github.com/Bajena/ams_lazy_relationships/tree/v0.1.4) (2019-06-02)
|
4
|
+
[Full Changelog](https://github.com/Bajena/ams_lazy_relationships/compare/v0.1.3...v0.1.4)
|
5
|
+
|
6
|
+
**Closed issues:**
|
7
|
+
|
8
|
+
- Use replace\_methods: false by default in loaders [\#28](https://github.com/Bajena/ams_lazy_relationships/issues/28)
|
9
|
+
- Require less restrictive batch-loader version [\#25](https://github.com/Bajena/ams_lazy_relationships/issues/25)
|
10
|
+
- Profile time and memory usage [\#21](https://github.com/Bajena/ams_lazy_relationships/issues/21)
|
11
|
+
- Loading circular relationships [\#20](https://github.com/Bajena/ams_lazy_relationships/issues/20)
|
12
|
+
- Add railtie [\#19](https://github.com/Bajena/ams_lazy_relationships/issues/19)
|
13
|
+
|
14
|
+
**Merged pull requests:**
|
15
|
+
|
16
|
+
- Use replace\_methods: false in batch loaders [\#29](https://github.com/Bajena/ams_lazy_relationships/pull/29) ([Bajena](https://github.com/Bajena))
|
17
|
+
- Add benchmark for speed & memory usage [\#27](https://github.com/Bajena/ams_lazy_relationships/pull/27) ([Bajena](https://github.com/Bajena))
|
18
|
+
- Require less restrictive batch loader version [\#26](https://github.com/Bajena/ams_lazy_relationships/pull/26) ([Bajena](https://github.com/Bajena))
|
19
|
+
|
3
20
|
## [v0.1.3](https://github.com/Bajena/ams_lazy_relationships/tree/v0.1.3) (2019-05-19)
|
4
21
|
[Full Changelog](https://github.com/Bajena/ams_lazy_relationships/compare/0.1.2...v0.1.3)
|
5
22
|
|
@@ -53,4 +70,4 @@
|
|
53
70
|
|
54
71
|
|
55
72
|
|
56
|
-
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
|
73
|
+
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
|
data/Gemfile.lock
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ams_lazy_relationships (0.1.
|
4
|
+
ams_lazy_relationships (0.1.4)
|
5
5
|
active_model_serializers
|
6
|
-
batch-loader (~> 1
|
6
|
+
batch-loader (~> 1)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
@@ -45,7 +45,9 @@ GEM
|
|
45
45
|
thor (>= 0.14.0)
|
46
46
|
arel (9.0.0)
|
47
47
|
ast (2.4.0)
|
48
|
-
batch-loader (1.
|
48
|
+
batch-loader (1.4.1)
|
49
|
+
benchmark-memory (0.1.2)
|
50
|
+
memory_profiler (~> 0.9)
|
49
51
|
builder (3.2.3)
|
50
52
|
case_transform (0.2)
|
51
53
|
activesupport
|
@@ -80,6 +82,7 @@ GEM
|
|
80
82
|
loofah (2.2.3)
|
81
83
|
crass (~> 1.0.2)
|
82
84
|
nokogiri (>= 1.5.9)
|
85
|
+
memory_profiler (0.9.13)
|
83
86
|
method_source (0.8.2)
|
84
87
|
mini_portile2 (2.4.0)
|
85
88
|
minitest (5.11.3)
|
@@ -181,6 +184,7 @@ DEPENDENCIES
|
|
181
184
|
activerecord
|
182
185
|
ams_lazy_relationships!
|
183
186
|
appraisal
|
187
|
+
benchmark-memory (~> 0.1)
|
184
188
|
bundler (~> 1.17)
|
185
189
|
db-query-matchers
|
186
190
|
github_changelog_generator
|
data/README.md
CHANGED
@@ -163,6 +163,36 @@ class BlogPostSerializer < BaseSerializer
|
|
163
163
|
end
|
164
164
|
```
|
165
165
|
|
166
|
+
## Performance comparison with vanilla AMS
|
167
|
+
|
168
|
+
In general the bigger and more complex your serialized records hierarchy is and the more latency you have in your DB the more you'll benefit from using this gem.
|
169
|
+
Example results for average size records tree (10 blog posts -> 10 comments each -> 1 user per comment, performed on local in-memory SQLite DB) are:
|
170
|
+
|
171
|
+
### Time:
|
172
|
+
|
173
|
+
```bash
|
174
|
+
# With lazy relationships: 0.860000 0.010000 0.870000 ( 0.870297)
|
175
|
+
# Vanilla AMS: 1.050000 0.000000 1.050000 ( 1.059801)
|
176
|
+
```
|
177
|
+
|
178
|
+
This means your serializers should get **~13%** speed boost by introducing lazy relationships.
|
179
|
+
|
180
|
+
### Memory:
|
181
|
+
|
182
|
+
```bash
|
183
|
+
# With lazy relationships:
|
184
|
+
# 46.283M memsize ( 0.000 retained)
|
185
|
+
# 506.696k objects ( 0.000 retained)
|
186
|
+
# 50.000 strings ( 0.000 retained)
|
187
|
+
# Vanilla AMS: 42.738M memsize ( 0.000 retained)
|
188
|
+
# 545.266k objects ( 0.000 retained)
|
189
|
+
# 50.000 strings ( 0.000 retained)
|
190
|
+
```
|
191
|
+
|
192
|
+
This means that serialization may consume **~5%** more memory.
|
193
|
+
|
194
|
+
Detailed benchmark script & results can be found [here](/spec/benchmark_spec.rb).
|
195
|
+
|
166
196
|
## Development
|
167
197
|
|
168
198
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/RELEASE.md
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# Release steps
|
2
|
+
1. Bump VERSION constant
|
3
|
+
2. Generate changelog and update
|
4
|
+
```shell
|
5
|
+
CHANGELOG_GITHUB_TOKEN=<token> bundle exec rake changelog
|
6
|
+
```
|
7
|
+
3. Run `bundle` to regenerate Gemfile.lock
|
8
|
+
4. Build and push to rubygems
|
9
|
+
```shell
|
10
|
+
gem build ams_lazy_relationships
|
11
|
+
gem push ams_lazy_relationships-x.y.z.gem
|
12
|
+
```
|
data/Rakefile
CHANGED
@@ -34,7 +34,7 @@ Gem::Specification.new do |spec|
|
|
34
34
|
spec.require_paths = ["lib"]
|
35
35
|
|
36
36
|
spec.add_dependency "active_model_serializers"
|
37
|
-
spec.add_dependency "batch-loader", "~> 1
|
37
|
+
spec.add_dependency "batch-loader", "~> 1"
|
38
38
|
|
39
39
|
spec.add_development_dependency "activerecord"
|
40
40
|
# A Ruby library for testing against different versions of dependencies
|
@@ -57,4 +57,6 @@ Gem::Specification.new do |spec|
|
|
57
57
|
spec.add_development_dependency "undercover"
|
58
58
|
# Dynamically build an Active Record model (with table) within a test context
|
59
59
|
spec.add_development_dependency "with_model", "~> 2.0"
|
60
|
+
|
61
|
+
spec.add_development_dependency "benchmark-memory", "~> 0.1"
|
60
62
|
end
|
@@ -20,7 +20,7 @@ module AmsLazyRelationships
|
|
20
20
|
# @param block [Proc] a block to execute when data is evaluated.
|
21
21
|
# Loaded data is yielded as a block argument.
|
22
22
|
def load(record, &block)
|
23
|
-
BatchLoader.for(record).batch(key: batch_key) do |records, loader|
|
23
|
+
BatchLoader.for(record).batch(key: batch_key, replace_methods: false) do |records, loader|
|
24
24
|
data = load_data(records, loader)
|
25
25
|
|
26
26
|
block&.call(data)
|
@@ -19,7 +19,7 @@ module AmsLazyRelationships
|
|
19
19
|
# @param block [Proc] a block to execute when data is evaluated.
|
20
20
|
# Loaded data is yielded as a block argument.
|
21
21
|
def load(record, &block)
|
22
|
-
BatchLoader.for(record).batch(key: cache_key(record)) do |records, loader|
|
22
|
+
BatchLoader.for(record).batch(key: cache_key(record), replace_methods: false) do |records, loader|
|
23
23
|
data = []
|
24
24
|
records.each do |r|
|
25
25
|
value = calculate_value(r)
|
@@ -23,7 +23,7 @@ module AmsLazyRelationships
|
|
23
23
|
# @param block [Proc] a block to execute when data is evaluated
|
24
24
|
# Loaded data is yielded as a block argument.
|
25
25
|
def load(record, &block)
|
26
|
-
BatchLoader.for(record).batch(key: cache_key(record)) do |records, loader|
|
26
|
+
BatchLoader.for(record).batch(key: cache_key(record), replace_methods: false) do |records, loader|
|
27
27
|
data = load_data(records)
|
28
28
|
|
29
29
|
block&.call(data)
|
@@ -20,7 +20,7 @@ module AmsLazyRelationships
|
|
20
20
|
# Loaded data is yielded as a block argument.
|
21
21
|
def load(record, &block)
|
22
22
|
key = "#{record.class}/#{association_class_name}"
|
23
|
-
BatchLoader.for(record).batch(key: key) do |records, loader|
|
23
|
+
BatchLoader.for(record).batch(key: key, replace_methods: false) do |records, loader|
|
24
24
|
data = load_data(records)
|
25
25
|
|
26
26
|
block&.call(data)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ams_lazy_relationships
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Bajena
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-06-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_model_serializers
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '1
|
33
|
+
version: '1'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '1
|
40
|
+
version: '1'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: activerecord
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -276,6 +276,20 @@ dependencies:
|
|
276
276
|
- - "~>"
|
277
277
|
- !ruby/object:Gem::Version
|
278
278
|
version: '2.0'
|
279
|
+
- !ruby/object:Gem::Dependency
|
280
|
+
name: benchmark-memory
|
281
|
+
requirement: !ruby/object:Gem::Requirement
|
282
|
+
requirements:
|
283
|
+
- - "~>"
|
284
|
+
- !ruby/object:Gem::Version
|
285
|
+
version: '0.1'
|
286
|
+
type: :development
|
287
|
+
prerelease: false
|
288
|
+
version_requirements: !ruby/object:Gem::Requirement
|
289
|
+
requirements:
|
290
|
+
- - "~>"
|
291
|
+
- !ruby/object:Gem::Version
|
292
|
+
version: '0.1'
|
279
293
|
description:
|
280
294
|
email:
|
281
295
|
executables: []
|
@@ -294,6 +308,7 @@ files:
|
|
294
308
|
- LICENSE
|
295
309
|
- LICENSE.txt
|
296
310
|
- README.md
|
311
|
+
- RELEASE.md
|
297
312
|
- Rakefile
|
298
313
|
- ams_lazy_relationships.gemspec
|
299
314
|
- bin/console
|