mongoid-eager-loading 0.1.0 → 0.1.1
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.
- data/Gemfile.lock +12 -13
- data/README.md +25 -4
- data/benchmark/benchmark.rb +57 -0
- data/lib/mongoid-eager-loading/version.rb +1 -1
- data/mongoid-eager-loading.gemspec +3 -2
- data/spec/models/person.rb +0 -1
- metadata +30 -11
data/Gemfile.lock
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
mongoid-eager-loading (0.1.
|
5
|
-
mongoid (~> 2.0.0.beta.
|
4
|
+
mongoid-eager-loading (0.1.1)
|
5
|
+
mongoid (~> 2.0.0.beta.19)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: http://rubygems.org/
|
@@ -16,16 +16,15 @@ GEM
|
|
16
16
|
bson_ext (1.1.1)
|
17
17
|
builder (2.1.2)
|
18
18
|
diff-lcs (1.1.2)
|
19
|
-
i18n (0.4.
|
19
|
+
i18n (0.4.2)
|
20
20
|
mocha (0.9.9)
|
21
21
|
rake
|
22
|
-
mongo (1.
|
23
|
-
bson (>= 1.
|
24
|
-
mongoid (2.0.0.
|
25
|
-
activemodel (
|
26
|
-
mongo (
|
27
|
-
|
28
|
-
will_paginate (~> 3.0.pre)
|
22
|
+
mongo (1.1.1)
|
23
|
+
bson (>= 1.1.1)
|
24
|
+
mongoid (2.0.0.alpha)
|
25
|
+
activemodel (>= 3.0.pre)
|
26
|
+
mongo (>= 0.19.1)
|
27
|
+
will_paginate (>= 3.0.pre)
|
29
28
|
rake (0.8.7)
|
30
29
|
rspec (2.0.1)
|
31
30
|
rspec-core (~> 2.0.1)
|
@@ -37,7 +36,6 @@ GEM
|
|
37
36
|
rspec-mocks (2.0.1)
|
38
37
|
rspec-core (~> 2.0.1)
|
39
38
|
rspec-expectations (~> 2.0.1)
|
40
|
-
tzinfo (0.3.23)
|
41
39
|
watchr (0.7)
|
42
40
|
will_paginate (3.0.pre2)
|
43
41
|
|
@@ -45,10 +43,11 @@ PLATFORMS
|
|
45
43
|
ruby
|
46
44
|
|
47
45
|
DEPENDENCIES
|
48
|
-
bson_ext
|
46
|
+
bson_ext (~> 1.1.1)
|
49
47
|
bundler (>= 1.0.0)
|
50
48
|
mocha
|
51
|
-
|
49
|
+
mongo (~> 1.1.1)
|
50
|
+
mongoid (~> 2.0.0.beta.19)
|
52
51
|
mongoid-eager-loading!
|
53
52
|
rspec (~> 2.0.0)
|
54
53
|
watchr
|
data/README.md
CHANGED
@@ -5,6 +5,8 @@ mongoid-eager-loading adds the eager loading feature for mongoid.
|
|
5
5
|
|
6
6
|
Originally it is my [pull request][0] for mongoid, but it is not accepted yet, so I created this gem to get the eager loading benefits easily for my projects.
|
7
7
|
|
8
|
+
I only test it in mongoid-2.0.0.beta.19, maybe you can try it on other mongoid version, and let me know if it works fine.
|
9
|
+
|
8
10
|
Usage
|
9
11
|
-----
|
10
12
|
|
@@ -12,17 +14,35 @@ define it in your Gemfile
|
|
12
14
|
|
13
15
|
gem "mongoid-eager-loading"
|
14
16
|
|
15
|
-
|
17
|
+
suppose you have a mongoid model Post
|
16
18
|
|
17
|
-
class
|
19
|
+
class Post
|
18
20
|
include Mongoid::Document
|
19
|
-
|
21
|
+
|
22
|
+
referenced_in :user
|
23
|
+
references_many :comments
|
20
24
|
end
|
21
25
|
|
22
26
|
then you can use the eager loading like
|
23
27
|
|
24
28
|
Post.includes(:user)
|
25
|
-
Post.includes(:user, :
|
29
|
+
Post.includes(:user, :comments)
|
30
|
+
|
31
|
+
eager loading can be only used on referenced_in, references_one and references_many associations.
|
32
|
+
|
33
|
+
Benchmark
|
34
|
+
---------
|
35
|
+
|
36
|
+
I also run a [benchmark][1] on my local computer, the result is as follows
|
37
|
+
|
38
|
+
Starting benchmark...
|
39
|
+
user system total real
|
40
|
+
Finding 10 posts with person, without eager loading 0.010000 0.000000 0.010000 ( 0.006538)
|
41
|
+
Finding 10 posts with person, with eager loading 0.000000 0.000000 0.000000 ( 0.005235)
|
42
|
+
Finding 50 posts with person, without eager loading 0.020000 0.000000 0.020000 ( 0.027912)
|
43
|
+
Finding 50 posts with person, with eager loading 0.020000 0.000000 0.020000 ( 0.020103)
|
44
|
+
Finding 100 posts with person, without eager loading 0.040000 0.000000 0.040000 ( 0.055197)
|
45
|
+
Finding 100 posts with person, with eager loading 0.030000 0.010000 0.040000 ( 0.040644)
|
26
46
|
|
27
47
|
Author
|
28
48
|
------
|
@@ -33,3 +53,4 @@ Copyright
|
|
33
53
|
Copyright (c) 2010 Richard Huang. See LICENSE for details.
|
34
54
|
|
35
55
|
[0]: https://github.com/mongoid/mongoid/pull/391
|
56
|
+
[1]: http://github.com/flyerhzm/mongoid-eager-loading/blob/master/benchmark/benchmark.rb
|
@@ -0,0 +1,57 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
|
2
|
+
require "rubygems"
|
3
|
+
require "benchmark"
|
4
|
+
require "mongoid"
|
5
|
+
require "mongoid-eager-loading"
|
6
|
+
|
7
|
+
Mongoid.configure do |config|
|
8
|
+
config.master = Mongo::Connection.new.db("mongoid_perf_test", :logger => Logger.new($stdout, :info))
|
9
|
+
end
|
10
|
+
|
11
|
+
Mongoid.master.collection("people").drop
|
12
|
+
Mongoid.master.collection("posts").drop
|
13
|
+
|
14
|
+
class Person
|
15
|
+
include Mongoid::Document
|
16
|
+
include Mongoid::Timestamps
|
17
|
+
field :name
|
18
|
+
references_many :posts
|
19
|
+
end
|
20
|
+
|
21
|
+
class Post
|
22
|
+
include Mongoid::Document
|
23
|
+
include Mongoid::Timestamps
|
24
|
+
field :title
|
25
|
+
referenced_in :person
|
26
|
+
end
|
27
|
+
|
28
|
+
10000.times do |n|
|
29
|
+
person = Person.create(:name => "Test_#{n}")
|
30
|
+
person.posts.create(:title => "Test_#{2*n}")
|
31
|
+
person.posts.create(:title => "Test_#{2*n+1}")
|
32
|
+
end
|
33
|
+
|
34
|
+
puts "Starting benchmark..."
|
35
|
+
Benchmark.bm(60) do |bm|
|
36
|
+
bm.report("Finding 10 posts with person, without eager loading") do
|
37
|
+
Post.limit(10).each { |p| p.person.name }
|
38
|
+
end
|
39
|
+
|
40
|
+
bm.report("Finding 10 posts with person, with eager loading") do
|
41
|
+
Post.limit(10).includes(:person).each { |p| p.person.name }
|
42
|
+
end
|
43
|
+
bm.report("Finding 50 posts with person, without eager loading") do
|
44
|
+
Post.limit(50).each { |p| p.person.name }
|
45
|
+
end
|
46
|
+
|
47
|
+
bm.report("Finding 50 posts with person, with eager loading") do
|
48
|
+
Post.limit(50).includes(:person).each { |p| p.person.name }
|
49
|
+
end
|
50
|
+
bm.report("Finding 100 posts with person, without eager loading") do
|
51
|
+
Post.limit(100).each { |p| p.person.name }
|
52
|
+
end
|
53
|
+
|
54
|
+
bm.report("Finding 100 posts with person, with eager loading") do
|
55
|
+
Post.limit(100).includes(:person).each { |p| p.person.name }
|
56
|
+
end
|
57
|
+
end
|
@@ -14,13 +14,14 @@ Gem::Specification.new do |s|
|
|
14
14
|
s.required_rubygems_version = ">= 1.3.6"
|
15
15
|
s.rubyforge_project = "mongoid-eager-loading"
|
16
16
|
|
17
|
-
s.add_dependency "mongoid", "~> 2.0.0.beta.
|
17
|
+
s.add_dependency "mongoid", "~> 2.0.0.beta.19"
|
18
18
|
|
19
19
|
s.add_development_dependency "bundler", ">= 1.0.0"
|
20
20
|
s.add_development_dependency "rspec", "~> 2.0.0"
|
21
21
|
s.add_development_dependency "mocha"
|
22
22
|
s.add_development_dependency "watchr"
|
23
|
-
s.add_development_dependency "bson_ext"
|
23
|
+
s.add_development_dependency "bson_ext", "~> 1.1.1"
|
24
|
+
s.add_development_dependency "mongo", "~> 1.1.1"
|
24
25
|
|
25
26
|
s.files = `git ls-files`.split("\n")
|
26
27
|
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
|
data/spec/models/person.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid-eager-loading
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Richard Huang
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-10-
|
18
|
+
date: 2010-10-27 00:00:00 +08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -24,14 +24,14 @@ dependencies:
|
|
24
24
|
requirements:
|
25
25
|
- - ~>
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
hash:
|
27
|
+
hash: 62196421
|
28
28
|
segments:
|
29
29
|
- 2
|
30
30
|
- 0
|
31
31
|
- 0
|
32
32
|
- beta
|
33
|
-
-
|
34
|
-
version: 2.0.0.beta.
|
33
|
+
- 19
|
34
|
+
version: 2.0.0.beta.19
|
35
35
|
name: mongoid
|
36
36
|
prerelease: false
|
37
37
|
type: :runtime
|
@@ -100,16 +100,34 @@ dependencies:
|
|
100
100
|
requirement: &id006 !ruby/object:Gem::Requirement
|
101
101
|
none: false
|
102
102
|
requirements:
|
103
|
-
- -
|
103
|
+
- - ~>
|
104
104
|
- !ruby/object:Gem::Version
|
105
|
-
hash:
|
105
|
+
hash: 17
|
106
106
|
segments:
|
107
|
-
-
|
108
|
-
|
107
|
+
- 1
|
108
|
+
- 1
|
109
|
+
- 1
|
110
|
+
version: 1.1.1
|
109
111
|
name: bson_ext
|
110
112
|
prerelease: false
|
111
113
|
type: :development
|
112
114
|
version_requirements: *id006
|
115
|
+
- !ruby/object:Gem::Dependency
|
116
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
117
|
+
none: false
|
118
|
+
requirements:
|
119
|
+
- - ~>
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
hash: 17
|
122
|
+
segments:
|
123
|
+
- 1
|
124
|
+
- 1
|
125
|
+
- 1
|
126
|
+
version: 1.1.1
|
127
|
+
name: mongo
|
128
|
+
prerelease: false
|
129
|
+
type: :development
|
130
|
+
version_requirements: *id007
|
113
131
|
description: eager loading for mongoid
|
114
132
|
email:
|
115
133
|
- flyerhzm@gmail.com
|
@@ -128,6 +146,7 @@ files:
|
|
128
146
|
- LICENSE
|
129
147
|
- README.md
|
130
148
|
- Rakefile
|
149
|
+
- benchmark/benchmark.rb
|
131
150
|
- lib/mongoid-eager-loading.rb
|
132
151
|
- lib/mongoid-eager-loading/mongoid/criteria.rb
|
133
152
|
- lib/mongoid-eager-loading/mongoid/criterion/eager_loading.rb
|