bullet 4.0.0 → 4.1.4
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/.gitignore +1 -0
- data/.travis.yml +4 -2
- data/Gemfile +2 -3
- data/Gemfile.lock +36 -39
- data/Gemfile.rails-2.3.14.lock +1 -1
- data/{Gemfile.rails-3.0.12 → Gemfile.rails-3.0.13} +1 -1
- data/{Gemfile.rails-3.0.12.lock → Gemfile.rails-3.0.13.lock} +27 -27
- data/{Gemfile.rails-3.1.4 → Gemfile.rails-3.1.5} +2 -2
- data/{Gemfile.rails-3.1.4.lock → Gemfile.rails-3.1.5.lock} +34 -34
- data/README.textile +3 -1
- data/README_for_rails2.textile +4 -0
- data/lib/bullet/action_controller2.rb +5 -4
- data/lib/bullet/dependency.rb +83 -0
- data/lib/bullet/{mongoid.rb → mongoid24.rb} +13 -15
- data/lib/bullet/mongoid3.rb +53 -0
- data/lib/bullet/rack.rb +8 -6
- data/lib/bullet/version.rb +1 -2
- data/lib/bullet.rb +12 -17
- data/spec/bullet/ext/object_spec.rb +1 -4
- data/spec/integration/association_spec.rb +1 -1
- data/spec/integration/counter_spec.rb +1 -1
- data/spec/integration/mongoid/association_spec.rb +174 -199
- data/spec/integration/rails2/association_spec.rb +1 -1
- data/spec/integration/rails2/counter_spec.rb +2 -2
- data/spec/models/post.rb +3 -1
- data/spec/spec_helper.rb +26 -22
- data/spec/support/mongo_seed.rb +10 -2
- data/test.sh +4 -0
- metadata +14 -12
- data/test.result +0 -2293
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,46 +1,43 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
bullet (4.
|
|
4
|
+
bullet (4.1.4)
|
|
5
5
|
uniform_notifier (~> 1.0.0)
|
|
6
6
|
|
|
7
7
|
GEM
|
|
8
8
|
remote: http://rubygems.org/
|
|
9
9
|
specs:
|
|
10
|
-
actionmailer (3.2.
|
|
11
|
-
actionpack (= 3.2.
|
|
10
|
+
actionmailer (3.2.5)
|
|
11
|
+
actionpack (= 3.2.5)
|
|
12
12
|
mail (~> 2.4.4)
|
|
13
|
-
actionpack (3.2.
|
|
14
|
-
activemodel (= 3.2.
|
|
15
|
-
activesupport (= 3.2.
|
|
13
|
+
actionpack (3.2.5)
|
|
14
|
+
activemodel (= 3.2.5)
|
|
15
|
+
activesupport (= 3.2.5)
|
|
16
16
|
builder (~> 3.0.0)
|
|
17
17
|
erubis (~> 2.7.0)
|
|
18
18
|
journey (~> 1.0.1)
|
|
19
19
|
rack (~> 1.4.0)
|
|
20
20
|
rack-cache (~> 1.2)
|
|
21
21
|
rack-test (~> 0.6.1)
|
|
22
|
-
sprockets (~> 2.1.
|
|
23
|
-
activemodel (3.2.
|
|
24
|
-
activesupport (= 3.2.
|
|
22
|
+
sprockets (~> 2.1.3)
|
|
23
|
+
activemodel (3.2.5)
|
|
24
|
+
activesupport (= 3.2.5)
|
|
25
25
|
builder (~> 3.0.0)
|
|
26
|
-
activerecord (3.2.
|
|
27
|
-
activemodel (= 3.2.
|
|
28
|
-
activesupport (= 3.2.
|
|
26
|
+
activerecord (3.2.5)
|
|
27
|
+
activemodel (= 3.2.5)
|
|
28
|
+
activesupport (= 3.2.5)
|
|
29
29
|
arel (~> 3.0.2)
|
|
30
30
|
tzinfo (~> 0.3.29)
|
|
31
31
|
activerecord-import (0.2.9)
|
|
32
32
|
activerecord (~> 3.0)
|
|
33
33
|
activerecord (~> 3.0)
|
|
34
|
-
activeresource (3.2.
|
|
35
|
-
activemodel (= 3.2.
|
|
36
|
-
activesupport (= 3.2.
|
|
37
|
-
activesupport (3.2.
|
|
34
|
+
activeresource (3.2.5)
|
|
35
|
+
activemodel (= 3.2.5)
|
|
36
|
+
activesupport (= 3.2.5)
|
|
37
|
+
activesupport (3.2.5)
|
|
38
38
|
i18n (~> 0.6)
|
|
39
39
|
multi_json (~> 1.0)
|
|
40
40
|
arel (3.0.2)
|
|
41
|
-
bson (1.6.2)
|
|
42
|
-
bson_ext (1.6.2)
|
|
43
|
-
bson (~> 1.6.2)
|
|
44
41
|
builder (3.0.0)
|
|
45
42
|
diff-lcs (1.1.3)
|
|
46
43
|
erubis (2.7.0)
|
|
@@ -53,20 +50,21 @@ GEM
|
|
|
53
50
|
hike (1.2.1)
|
|
54
51
|
i18n (0.6.0)
|
|
55
52
|
journey (1.0.3)
|
|
56
|
-
json (1.7.
|
|
53
|
+
json (1.7.3)
|
|
57
54
|
mail (2.4.4)
|
|
58
55
|
i18n (>= 0.4.0)
|
|
59
56
|
mime-types (~> 1.16)
|
|
60
57
|
treetop (~> 1.4.8)
|
|
61
58
|
mime-types (1.18)
|
|
62
|
-
|
|
63
|
-
bson (~> 1.6.2)
|
|
64
|
-
mongoid (2.4.9)
|
|
59
|
+
mongoid (3.0.0.rc)
|
|
65
60
|
activemodel (~> 3.1)
|
|
66
|
-
|
|
61
|
+
moped (~> 1.0.0.rc)
|
|
62
|
+
origin (~> 1.0.0.rc)
|
|
67
63
|
tzinfo (~> 0.3.22)
|
|
68
|
-
|
|
64
|
+
moped (1.0.0.rc)
|
|
65
|
+
multi_json (1.3.6)
|
|
69
66
|
mysql (2.8.1)
|
|
67
|
+
origin (1.0.0.rc)
|
|
70
68
|
perftools.rb (2.0.0)
|
|
71
69
|
polyglot (0.3.3)
|
|
72
70
|
rack (1.4.1)
|
|
@@ -76,21 +74,21 @@ GEM
|
|
|
76
74
|
rack
|
|
77
75
|
rack-test (0.6.1)
|
|
78
76
|
rack (>= 1.0)
|
|
79
|
-
rails (3.2.
|
|
80
|
-
actionmailer (= 3.2.
|
|
81
|
-
actionpack (= 3.2.
|
|
82
|
-
activerecord (= 3.2.
|
|
83
|
-
activeresource (= 3.2.
|
|
84
|
-
activesupport (= 3.2.
|
|
77
|
+
rails (3.2.5)
|
|
78
|
+
actionmailer (= 3.2.5)
|
|
79
|
+
actionpack (= 3.2.5)
|
|
80
|
+
activerecord (= 3.2.5)
|
|
81
|
+
activeresource (= 3.2.5)
|
|
82
|
+
activesupport (= 3.2.5)
|
|
85
83
|
bundler (~> 1.0)
|
|
86
|
-
railties (= 3.2.
|
|
87
|
-
railties (3.2.
|
|
88
|
-
actionpack (= 3.2.
|
|
89
|
-
activesupport (= 3.2.
|
|
84
|
+
railties (= 3.2.5)
|
|
85
|
+
railties (3.2.5)
|
|
86
|
+
actionpack (= 3.2.5)
|
|
87
|
+
activesupport (= 3.2.5)
|
|
90
88
|
rack-ssl (~> 1.3.2)
|
|
91
89
|
rake (>= 0.8.7)
|
|
92
90
|
rdoc (~> 3.4)
|
|
93
|
-
thor (
|
|
91
|
+
thor (>= 0.14.6, < 2.0)
|
|
94
92
|
rake (0.9.2.2)
|
|
95
93
|
rdoc (3.12)
|
|
96
94
|
json (~> 1.4)
|
|
@@ -120,13 +118,12 @@ PLATFORMS
|
|
|
120
118
|
|
|
121
119
|
DEPENDENCIES
|
|
122
120
|
activerecord-import
|
|
123
|
-
bson_ext
|
|
124
121
|
bullet!
|
|
125
122
|
guard
|
|
126
123
|
guard-rspec
|
|
127
|
-
mongoid
|
|
124
|
+
mongoid (= 3.0.0.rc)
|
|
128
125
|
mysql
|
|
129
126
|
perftools.rb
|
|
130
|
-
rails (= 3.2.
|
|
127
|
+
rails (= 3.2.5)
|
|
131
128
|
rspec
|
|
132
129
|
sqlite3
|
data/Gemfile.rails-2.3.14.lock
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
bullet (
|
|
4
|
+
bullet (4.1.4)
|
|
5
5
|
uniform_notifier (~> 1.0.0)
|
|
6
6
|
|
|
7
7
|
GEM
|
|
8
8
|
remote: http://rubygems.org/
|
|
9
9
|
specs:
|
|
10
10
|
abstract (1.0.0)
|
|
11
|
-
actionmailer (3.0.
|
|
12
|
-
actionpack (= 3.0.
|
|
11
|
+
actionmailer (3.0.13)
|
|
12
|
+
actionpack (= 3.0.13)
|
|
13
13
|
mail (~> 2.2.19)
|
|
14
|
-
actionpack (3.0.
|
|
15
|
-
activemodel (= 3.0.
|
|
16
|
-
activesupport (= 3.0.
|
|
14
|
+
actionpack (3.0.13)
|
|
15
|
+
activemodel (= 3.0.13)
|
|
16
|
+
activesupport (= 3.0.13)
|
|
17
17
|
builder (~> 2.1.2)
|
|
18
18
|
erubis (~> 2.6.6)
|
|
19
19
|
i18n (~> 0.5.0)
|
|
@@ -21,22 +21,22 @@ GEM
|
|
|
21
21
|
rack-mount (~> 0.6.14)
|
|
22
22
|
rack-test (~> 0.5.7)
|
|
23
23
|
tzinfo (~> 0.3.23)
|
|
24
|
-
activemodel (3.0.
|
|
25
|
-
activesupport (= 3.0.
|
|
24
|
+
activemodel (3.0.13)
|
|
25
|
+
activesupport (= 3.0.13)
|
|
26
26
|
builder (~> 2.1.2)
|
|
27
27
|
i18n (~> 0.5.0)
|
|
28
|
-
activerecord (3.0.
|
|
29
|
-
activemodel (= 3.0.
|
|
30
|
-
activesupport (= 3.0.
|
|
28
|
+
activerecord (3.0.13)
|
|
29
|
+
activemodel (= 3.0.13)
|
|
30
|
+
activesupport (= 3.0.13)
|
|
31
31
|
arel (~> 2.0.10)
|
|
32
32
|
tzinfo (~> 0.3.23)
|
|
33
33
|
activerecord-import (0.2.9)
|
|
34
34
|
activerecord (~> 3.0)
|
|
35
35
|
activerecord (~> 3.0)
|
|
36
|
-
activeresource (3.0.
|
|
37
|
-
activemodel (= 3.0.
|
|
38
|
-
activesupport (= 3.0.
|
|
39
|
-
activesupport (3.0.
|
|
36
|
+
activeresource (3.0.13)
|
|
37
|
+
activemodel (= 3.0.13)
|
|
38
|
+
activesupport (= 3.0.13)
|
|
39
|
+
activesupport (3.0.13)
|
|
40
40
|
arel (2.0.10)
|
|
41
41
|
bson (1.6.2)
|
|
42
42
|
bson_ext (1.6.2)
|
|
@@ -52,7 +52,7 @@ GEM
|
|
|
52
52
|
guard-rspec (0.7.0)
|
|
53
53
|
guard (>= 0.10.0)
|
|
54
54
|
i18n (0.5.0)
|
|
55
|
-
json (1.7.
|
|
55
|
+
json (1.7.3)
|
|
56
56
|
mail (2.2.19)
|
|
57
57
|
activesupport (>= 2.3.6)
|
|
58
58
|
i18n (>= 0.4.0)
|
|
@@ -67,17 +67,17 @@ GEM
|
|
|
67
67
|
rack (>= 1.0.0)
|
|
68
68
|
rack-test (0.5.7)
|
|
69
69
|
rack (>= 1.0)
|
|
70
|
-
rails (3.0.
|
|
71
|
-
actionmailer (= 3.0.
|
|
72
|
-
actionpack (= 3.0.
|
|
73
|
-
activerecord (= 3.0.
|
|
74
|
-
activeresource (= 3.0.
|
|
75
|
-
activesupport (= 3.0.
|
|
70
|
+
rails (3.0.13)
|
|
71
|
+
actionmailer (= 3.0.13)
|
|
72
|
+
actionpack (= 3.0.13)
|
|
73
|
+
activerecord (= 3.0.13)
|
|
74
|
+
activeresource (= 3.0.13)
|
|
75
|
+
activesupport (= 3.0.13)
|
|
76
76
|
bundler (~> 1.0)
|
|
77
|
-
railties (= 3.0.
|
|
78
|
-
railties (3.0.
|
|
79
|
-
actionpack (= 3.0.
|
|
80
|
-
activesupport (= 3.0.
|
|
77
|
+
railties (= 3.0.13)
|
|
78
|
+
railties (3.0.13)
|
|
79
|
+
actionpack (= 3.0.13)
|
|
80
|
+
activesupport (= 3.0.13)
|
|
81
81
|
rake (>= 0.8.7)
|
|
82
82
|
rdoc (~> 3.4)
|
|
83
83
|
thor (~> 0.14.4)
|
|
@@ -111,6 +111,6 @@ DEPENDENCIES
|
|
|
111
111
|
guard-rspec
|
|
112
112
|
mysql
|
|
113
113
|
perftools.rb
|
|
114
|
-
rails (= 3.0.
|
|
114
|
+
rails (= 3.0.13)
|
|
115
115
|
rspec
|
|
116
116
|
sqlite3
|
|
@@ -1,43 +1,43 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
bullet (
|
|
4
|
+
bullet (4.1.4)
|
|
5
5
|
uniform_notifier (~> 1.0.0)
|
|
6
6
|
|
|
7
7
|
GEM
|
|
8
8
|
remote: http://rubygems.org/
|
|
9
9
|
specs:
|
|
10
|
-
actionmailer (3.1.
|
|
11
|
-
actionpack (= 3.1.
|
|
12
|
-
mail (~> 2.3.
|
|
13
|
-
actionpack (3.1.
|
|
14
|
-
activemodel (= 3.1.
|
|
15
|
-
activesupport (= 3.1.
|
|
10
|
+
actionmailer (3.1.5)
|
|
11
|
+
actionpack (= 3.1.5)
|
|
12
|
+
mail (~> 2.3.3)
|
|
13
|
+
actionpack (3.1.5)
|
|
14
|
+
activemodel (= 3.1.5)
|
|
15
|
+
activesupport (= 3.1.5)
|
|
16
16
|
builder (~> 3.0.0)
|
|
17
17
|
erubis (~> 2.7.0)
|
|
18
18
|
i18n (~> 0.6)
|
|
19
19
|
rack (~> 1.3.6)
|
|
20
|
-
rack-cache (~> 1.
|
|
20
|
+
rack-cache (~> 1.2)
|
|
21
21
|
rack-mount (~> 0.8.2)
|
|
22
22
|
rack-test (~> 0.6.1)
|
|
23
|
-
sprockets (~> 2.0.
|
|
24
|
-
activemodel (3.1.
|
|
25
|
-
activesupport (= 3.1.
|
|
23
|
+
sprockets (~> 2.0.4)
|
|
24
|
+
activemodel (3.1.5)
|
|
25
|
+
activesupport (= 3.1.5)
|
|
26
26
|
builder (~> 3.0.0)
|
|
27
27
|
i18n (~> 0.6)
|
|
28
|
-
activerecord (3.1.
|
|
29
|
-
activemodel (= 3.1.
|
|
30
|
-
activesupport (= 3.1.
|
|
28
|
+
activerecord (3.1.5)
|
|
29
|
+
activemodel (= 3.1.5)
|
|
30
|
+
activesupport (= 3.1.5)
|
|
31
31
|
arel (~> 2.2.3)
|
|
32
32
|
tzinfo (~> 0.3.29)
|
|
33
33
|
activerecord-import (0.2.9)
|
|
34
34
|
activerecord (~> 3.0)
|
|
35
35
|
activerecord (~> 3.0)
|
|
36
|
-
activeresource (3.1.
|
|
37
|
-
activemodel (= 3.1.
|
|
38
|
-
activesupport (= 3.1.
|
|
39
|
-
activesupport (3.1.
|
|
40
|
-
multi_json (
|
|
36
|
+
activeresource (3.1.5)
|
|
37
|
+
activemodel (= 3.1.5)
|
|
38
|
+
activesupport (= 3.1.5)
|
|
39
|
+
activesupport (3.1.5)
|
|
40
|
+
multi_json (>= 1.0, < 1.3)
|
|
41
41
|
arel (2.2.3)
|
|
42
42
|
bson (1.6.2)
|
|
43
43
|
bson_ext (1.6.2)
|
|
@@ -53,7 +53,7 @@ GEM
|
|
|
53
53
|
guard (>= 0.10.0)
|
|
54
54
|
hike (1.2.1)
|
|
55
55
|
i18n (0.6.0)
|
|
56
|
-
json (1.7.
|
|
56
|
+
json (1.7.3)
|
|
57
57
|
mail (2.3.3)
|
|
58
58
|
i18n (>= 0.4.0)
|
|
59
59
|
mime-types (~> 1.16)
|
|
@@ -61,11 +61,11 @@ GEM
|
|
|
61
61
|
mime-types (1.18)
|
|
62
62
|
mongo (1.6.2)
|
|
63
63
|
bson (~> 1.6.2)
|
|
64
|
-
mongoid (2.4.
|
|
64
|
+
mongoid (2.4.10)
|
|
65
65
|
activemodel (~> 3.1)
|
|
66
66
|
mongo (~> 1.3)
|
|
67
67
|
tzinfo (~> 0.3.22)
|
|
68
|
-
multi_json (1.
|
|
68
|
+
multi_json (1.2.0)
|
|
69
69
|
mysql (2.8.1)
|
|
70
70
|
perftools.rb (2.0.0)
|
|
71
71
|
polyglot (0.3.3)
|
|
@@ -78,17 +78,17 @@ GEM
|
|
|
78
78
|
rack
|
|
79
79
|
rack-test (0.6.1)
|
|
80
80
|
rack (>= 1.0)
|
|
81
|
-
rails (3.1.
|
|
82
|
-
actionmailer (= 3.1.
|
|
83
|
-
actionpack (= 3.1.
|
|
84
|
-
activerecord (= 3.1.
|
|
85
|
-
activeresource (= 3.1.
|
|
86
|
-
activesupport (= 3.1.
|
|
81
|
+
rails (3.1.5)
|
|
82
|
+
actionmailer (= 3.1.5)
|
|
83
|
+
actionpack (= 3.1.5)
|
|
84
|
+
activerecord (= 3.1.5)
|
|
85
|
+
activeresource (= 3.1.5)
|
|
86
|
+
activesupport (= 3.1.5)
|
|
87
87
|
bundler (~> 1.0)
|
|
88
|
-
railties (= 3.1.
|
|
89
|
-
railties (3.1.
|
|
90
|
-
actionpack (= 3.1.
|
|
91
|
-
activesupport (= 3.1.
|
|
88
|
+
railties (= 3.1.5)
|
|
89
|
+
railties (3.1.5)
|
|
90
|
+
actionpack (= 3.1.5)
|
|
91
|
+
activesupport (= 3.1.5)
|
|
92
92
|
rack-ssl (~> 1.3.2)
|
|
93
93
|
rake (>= 0.8.7)
|
|
94
94
|
rdoc (~> 3.4)
|
|
@@ -126,9 +126,9 @@ DEPENDENCIES
|
|
|
126
126
|
bullet!
|
|
127
127
|
guard
|
|
128
128
|
guard-rspec
|
|
129
|
-
mongoid
|
|
129
|
+
mongoid (= 2.4.10)
|
|
130
130
|
mysql
|
|
131
131
|
perftools.rb
|
|
132
|
-
rails (= 3.1.
|
|
132
|
+
rails (= 3.1.5)
|
|
133
133
|
rspec
|
|
134
134
|
sqlite3
|
data/README.textile
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
h1. Bullet
|
|
1
|
+
h1. Bullet
|
|
2
2
|
|
|
3
3
|
!https://secure.travis-ci.org/flyerhzm/bullet.png!:http://travis-ci.org/flyerhzm/bullet
|
|
4
4
|
|
|
5
|
+
!http://api.coderwall.com/flyerhzm/endorsecount.png!:http://coderwall.com/flyerhzm
|
|
6
|
+
|
|
5
7
|
The Bullet gem is designed to help you increase your application's performance by reducing the number of queries it makes. It will watch your queries while you develop your application and notify you when you should add eager loading (N+1 queries), when you're using eager loading that isn't necessary and when you should use counter cache.
|
|
6
8
|
|
|
7
9
|
Best practice is to use Bullet in development mode or custom mode (staging, profile, etc.). The last thing you want is your clients getting alerts about how lazy you are.
|
data/README_for_rails2.textile
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
h1. Bullet
|
|
2
2
|
|
|
3
|
+
!https://secure.travis-ci.org/flyerhzm/bullet.png!:http://travis-ci.org/flyerhzm/bullet
|
|
4
|
+
|
|
5
|
+
!http://api.coderwall.com/flyerhzm/endorsecount.png!:http://coderwall.com/flyerhzm
|
|
6
|
+
|
|
3
7
|
The Bullet plugin/gem is designed to help you increase your application's performance by reducing the number of queries it makes. It will watch your queries while you develop your application and notify you when you should add eager loading (N+1 queries), when you're using eager loading that isn't necessary and when you should use counter cache.
|
|
4
8
|
|
|
5
9
|
Best practice is to use Bullet in development mode or custom mode (staging, profile, etc.). The last thing you want is your clients getting alerts about how lazy you are.
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
module Bullet
|
|
2
2
|
class ActionController
|
|
3
|
+
extend Dependency
|
|
4
|
+
|
|
3
5
|
def self.enable
|
|
4
6
|
require 'action_controller'
|
|
5
|
-
if
|
|
7
|
+
if active_record23?
|
|
6
8
|
::ActionController::Dispatcher.middleware.use Bullet::Rack
|
|
7
9
|
::ActionController::Dispatcher.class_eval do
|
|
8
10
|
class <<self
|
|
@@ -13,7 +15,7 @@ module Bullet
|
|
|
13
15
|
end
|
|
14
16
|
end
|
|
15
17
|
end
|
|
16
|
-
elsif
|
|
18
|
+
elsif active_record21? || active_record22?
|
|
17
19
|
::ActionController::Dispatcher.class_eval do
|
|
18
20
|
alias_method :origin_reload_application, :reload_application
|
|
19
21
|
def reload_application
|
|
@@ -29,8 +31,7 @@ module Bullet
|
|
|
29
31
|
response = origin_process(request, response, method = :perform_action, *arguments)
|
|
30
32
|
|
|
31
33
|
if Bullet.notification?
|
|
32
|
-
if response.headers["type"] && response.headers["type"].include?('text/html') &&
|
|
33
|
-
response.body.include?("<html>") && response.body.include?("</html>")
|
|
34
|
+
if response.headers["type"] && response.headers["type"].include?('text/html') && response.body.include?("<html>")
|
|
34
35
|
response.body <<= Bullet.gather_inline_notifications
|
|
35
36
|
response.headers["Content-Length"] = response.body.length.to_s
|
|
36
37
|
end
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
module Bullet
|
|
2
|
+
module Dependency
|
|
3
|
+
def mongoid?
|
|
4
|
+
@mongoid ||= begin
|
|
5
|
+
require 'mongoid'
|
|
6
|
+
true
|
|
7
|
+
rescue LoadError
|
|
8
|
+
false
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def active_record?
|
|
13
|
+
@active_record ||= begin
|
|
14
|
+
require 'active_record'
|
|
15
|
+
true
|
|
16
|
+
rescue LoadError
|
|
17
|
+
false
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def active_record_version
|
|
22
|
+
@active_record_version ||= begin
|
|
23
|
+
if active_record2?
|
|
24
|
+
'active_record2'
|
|
25
|
+
elsif active_record30?
|
|
26
|
+
'active_record3'
|
|
27
|
+
elsif active_record31? || active_record32?
|
|
28
|
+
'active_record31'
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def mongoid_version
|
|
34
|
+
@mongoid_version ||= begin
|
|
35
|
+
if mongoid24?
|
|
36
|
+
'mongoid24'
|
|
37
|
+
elsif mongoid3?
|
|
38
|
+
'mongoid3'
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def active_record2?
|
|
44
|
+
::ActiveRecord::VERSION::MAJOR == 2
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def active_record23?
|
|
48
|
+
active_record2? && ::ActiveRecord::VERSION::MINOR == 3
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def active_record22?
|
|
52
|
+
active_record2? && ::ActiveRecord::VERSION::MINOR == 2
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def active_record21?
|
|
56
|
+
active_record2? && ::ActiveRecord::VERSION::MINOR == 1
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def active_record3?
|
|
60
|
+
::ActiveRecord::VERSION::MAJOR == 3
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def active_record30?
|
|
64
|
+
active_record3? && ::ActiveRecord::VERSION::MINOR == 0
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def active_record31?
|
|
68
|
+
active_record3? && ::ActiveRecord::VERSION::MINOR == 1
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def active_record32?
|
|
72
|
+
active_record3? && ::ActiveRecord::VERSION::MINOR == 2
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def mongoid24?
|
|
76
|
+
::Mongoid::VERSION =~ /\A2\.4/
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def mongoid3?
|
|
80
|
+
::Mongoid::VERSION =~ /\A3/
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
@@ -2,20 +2,22 @@ module Bullet
|
|
|
2
2
|
module Mongoid
|
|
3
3
|
def self.enable
|
|
4
4
|
require 'mongoid'
|
|
5
|
+
|
|
5
6
|
::Mongoid::Contexts::Mongo.class_eval do
|
|
6
7
|
alias_method :origin_first, :first
|
|
7
8
|
alias_method :origin_last, :last
|
|
8
9
|
alias_method :origin_iterate, :iterate
|
|
10
|
+
alias_method :origin_eager_load, :eager_load
|
|
9
11
|
|
|
10
12
|
def first
|
|
11
13
|
result = origin_first
|
|
12
|
-
Bullet::Detector::Association.add_impossible_object(result)
|
|
14
|
+
Bullet::Detector::Association.add_impossible_object(result) if result
|
|
13
15
|
result
|
|
14
16
|
end
|
|
15
17
|
|
|
16
18
|
def last
|
|
17
19
|
result = origin_last
|
|
18
|
-
Bullet::Detector::Association.add_impossible_object(result)
|
|
20
|
+
Bullet::Detector::Association.add_impossible_object(result) if result
|
|
19
21
|
result
|
|
20
22
|
end
|
|
21
23
|
|
|
@@ -28,19 +30,6 @@ module Bullet
|
|
|
28
30
|
end
|
|
29
31
|
origin_iterate(&block)
|
|
30
32
|
end
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
::Mongoid::Relations::Accessors.class_eval do
|
|
34
|
-
alias_method :origin_set_relation, :set_relation
|
|
35
|
-
|
|
36
|
-
def set_relation(name, relation)
|
|
37
|
-
Bullet::Detector::NPlusOneQuery.call_association(self, name)
|
|
38
|
-
origin_set_relation(name, relation)
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
::Mongoid::Contexts::Mongo.class_eval do
|
|
43
|
-
alias_method :origin_eager_load, :eager_load
|
|
44
33
|
|
|
45
34
|
def eager_load(docs)
|
|
46
35
|
associations = criteria.inclusions.map(&:name)
|
|
@@ -51,6 +40,15 @@ module Bullet
|
|
|
51
40
|
origin_eager_load(docs)
|
|
52
41
|
end
|
|
53
42
|
end
|
|
43
|
+
|
|
44
|
+
::Mongoid::Relations::Accessors.class_eval do
|
|
45
|
+
alias_method :origin_set_relation, :set_relation
|
|
46
|
+
|
|
47
|
+
def set_relation(name, relation)
|
|
48
|
+
Bullet::Detector::NPlusOneQuery.call_association(self, name)
|
|
49
|
+
origin_set_relation(name, relation)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
54
52
|
end
|
|
55
53
|
end
|
|
56
54
|
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
module Bullet
|
|
2
|
+
module Mongoid
|
|
3
|
+
def self.enable
|
|
4
|
+
require 'mongoid'
|
|
5
|
+
::Mongoid::Contextual::Mongo.class_eval do
|
|
6
|
+
alias_method :origin_first, :first
|
|
7
|
+
alias_method :origin_last, :last
|
|
8
|
+
alias_method :origin_each, :each
|
|
9
|
+
alias_method :origin_eager_load, :eager_load
|
|
10
|
+
|
|
11
|
+
def first
|
|
12
|
+
result = origin_first
|
|
13
|
+
Bullet::Detector::Association.add_impossible_object(result) if result
|
|
14
|
+
result
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def last
|
|
18
|
+
result = origin_last
|
|
19
|
+
Bullet::Detector::Association.add_impossible_object(result) if result
|
|
20
|
+
result
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def each(&block)
|
|
24
|
+
records = query.map{ |doc| ::Mongoid::Factory.from_db(klass, doc) }
|
|
25
|
+
if records.length > 1
|
|
26
|
+
Bullet::Detector::Association.add_possible_objects(records)
|
|
27
|
+
elsif records.size == 1
|
|
28
|
+
Bullet::Detector::Association.add_impossible_object(records.first)
|
|
29
|
+
end
|
|
30
|
+
origin_each(&block)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def eager_load(docs)
|
|
34
|
+
associations = criteria.inclusions.map(&:name)
|
|
35
|
+
docs.each do |doc|
|
|
36
|
+
Bullet::Detector::Association.add_object_associations(doc, associations)
|
|
37
|
+
end
|
|
38
|
+
Bullet::Detector::Association.add_eager_loadings(docs, associations)
|
|
39
|
+
origin_eager_load(docs)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
::Mongoid::Relations::Accessors.class_eval do
|
|
44
|
+
alias_method :origin_set_relation, :set_relation
|
|
45
|
+
|
|
46
|
+
def set_relation(name, relation)
|
|
47
|
+
Bullet::Detector::NPlusOneQuery.call_association(self, name)
|
|
48
|
+
origin_set_relation(name, relation)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|