bullet 5.8.1 → 5.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +2 -1
- data/Gemfile.mongoid-7.0 +15 -0
- data/lib/bullet/dependency.rb +6 -0
- data/lib/bullet/mongoid7x.rb +61 -0
- data/lib/bullet/version.rb +1 -1
- data/test.sh +1 -0
- data/update.sh +1 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fefb038c3c46f100cc22cdd95c417c781aff2943
|
4
|
+
data.tar.gz: ad23b5755c4956788bad2b3ae98323d6e24c2bb8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79f4e0bb1d4e62df6460fd668f0789936e3e0b1c36d078bb13ec2788f9d69f46e0dd3615e1983019bc4c83d6e7d2b2195377c5216a23038d270aee2ddfb6e77c
|
7
|
+
data.tar.gz: 504905ca503f0727e71c1c476ab058eab57618bc6a4a9084411c479ebd63913c75ac178cf27566d05e800887e1d6f1e709aa89733632743c7216db810d410fb8
|
data/CHANGELOG.md
CHANGED
data/Gemfile.mongoid-7.0
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
gemspec
|
4
|
+
|
5
|
+
gem 'rails', '~> 5.0'
|
6
|
+
gem 'sqlite3', platforms: [:ruby]
|
7
|
+
gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
|
8
|
+
gem 'mongoid', '~> 7.0.0'
|
9
|
+
|
10
|
+
gem "rspec"
|
11
|
+
|
12
|
+
platforms :rbx do
|
13
|
+
gem 'rubysl', '~> 2.0'
|
14
|
+
gem 'rubinius-developer_tools'
|
15
|
+
end
|
data/lib/bullet/dependency.rb
CHANGED
@@ -42,6 +42,8 @@ module Bullet
|
|
42
42
|
'mongoid5x'
|
43
43
|
elsif mongoid6x?
|
44
44
|
'mongoid6x'
|
45
|
+
elsif mongoid7x?
|
46
|
+
'mongoid7x'
|
45
47
|
else
|
46
48
|
raise "Bullet does not support mongoid #{::Mongoid::VERSION} yet"
|
47
49
|
end
|
@@ -91,5 +93,9 @@ module Bullet
|
|
91
93
|
def mongoid6x?
|
92
94
|
mongoid? && ::Mongoid::VERSION =~ /\A6/
|
93
95
|
end
|
96
|
+
|
97
|
+
def mongoid7x?
|
98
|
+
mongoid? && ::Mongoid::VERSION =~ /\A7/
|
99
|
+
end
|
94
100
|
end
|
95
101
|
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bullet
|
4
|
+
module Mongoid
|
5
|
+
def self.enable
|
6
|
+
require 'mongoid'
|
7
|
+
::Mongoid::Contextual::Mongo.class_eval do
|
8
|
+
alias_method :origin_first, :first
|
9
|
+
alias_method :origin_last, :last
|
10
|
+
alias_method :origin_each, :each
|
11
|
+
alias_method :origin_eager_load, :eager_load
|
12
|
+
|
13
|
+
def first(opts = {})
|
14
|
+
result = origin_first(opts)
|
15
|
+
Bullet::Detector::NPlusOneQuery.add_impossible_object(result) if result
|
16
|
+
result
|
17
|
+
end
|
18
|
+
|
19
|
+
def last(opts = {})
|
20
|
+
result = origin_last(opts)
|
21
|
+
Bullet::Detector::NPlusOneQuery.add_impossible_object(result) if result
|
22
|
+
result
|
23
|
+
end
|
24
|
+
|
25
|
+
def each(&block)
|
26
|
+
return to_enum unless block_given?
|
27
|
+
|
28
|
+
records = []
|
29
|
+
origin_each { |record| records << record }
|
30
|
+
if records.length > 1
|
31
|
+
Bullet::Detector::NPlusOneQuery.add_possible_objects(records)
|
32
|
+
elsif records.size == 1
|
33
|
+
Bullet::Detector::NPlusOneQuery.add_impossible_object(records.first)
|
34
|
+
end
|
35
|
+
records.each(&block)
|
36
|
+
end
|
37
|
+
|
38
|
+
def eager_load(docs)
|
39
|
+
associations = criteria.inclusions.map(&:name)
|
40
|
+
docs.each do |doc|
|
41
|
+
Bullet::Detector::NPlusOneQuery.add_object_associations(doc, associations)
|
42
|
+
end
|
43
|
+
Bullet::Detector::UnusedEagerLoading.add_eager_loadings(docs, associations)
|
44
|
+
origin_eager_load(docs)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
::Mongoid::Association::Accessors.class_eval do
|
49
|
+
alias_method :origin_get_relation, :get_relation
|
50
|
+
|
51
|
+
def get_relation(name, association, object, reload = false)
|
52
|
+
result = origin_get_relation(name, association, object, reload)
|
53
|
+
unless association.embedded?
|
54
|
+
Bullet::Detector::NPlusOneQuery.call_association(self, name)
|
55
|
+
end
|
56
|
+
result
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/lib/bullet/version.rb
CHANGED
data/test.sh
CHANGED
@@ -6,6 +6,7 @@ BUNDLE_GEMFILE=Gemfile.rails-5.0 bundle && BUNDLE_GEMFILE=Gemfile.rails-5.0 bund
|
|
6
6
|
BUNDLE_GEMFILE=Gemfile.rails-4.2 bundle && BUNDLE_GEMFILE=Gemfile.rails-4.2 bundle exec rspec spec
|
7
7
|
BUNDLE_GEMFILE=Gemfile.rails-4.1 bundle && BUNDLE_GEMFILE=Gemfile.rails-4.1 bundle exec rspec spec
|
8
8
|
BUNDLE_GEMFILE=Gemfile.rails-4.0 bundle && BUNDLE_GEMFILE=Gemfile.rails-4.0 bundle exec rspec spec
|
9
|
+
BUNDLE_GEMFILE=Gemfile.mongoid-7.0 bundle && BUNDLE_GEMFILE=Gemfile.mongoid-7.0 bundle exec rspec spec
|
9
10
|
BUNDLE_GEMFILE=Gemfile.mongoid-6.0 bundle && BUNDLE_GEMFILE=Gemfile.mongoid-6.0 bundle exec rspec spec
|
10
11
|
BUNDLE_GEMFILE=Gemfile.mongoid-5.0 bundle && BUNDLE_GEMFILE=Gemfile.mongoid-5.0 bundle exec rspec spec
|
11
12
|
BUNDLE_GEMFILE=Gemfile.mongoid-4.0 bundle && BUNDLE_GEMFILE=Gemfile.mongoid-4.0 bundle exec rspec spec
|
data/update.sh
CHANGED
@@ -4,6 +4,7 @@ BUNDLE_GEMFILE=Gemfile.rails-5.0 bundle update
|
|
4
4
|
BUNDLE_GEMFILE=Gemfile.rails-4.2 bundle update
|
5
5
|
BUNDLE_GEMFILE=Gemfile.rails-4.1 bundle update
|
6
6
|
BUNDLE_GEMFILE=Gemfile.rails-4.0 bundle update
|
7
|
+
BUNDLE_GEMFILE=Gemfile.mongoid-7.0 bundle update
|
7
8
|
BUNDLE_GEMFILE=Gemfile.mongoid-6.0 bundle update
|
8
9
|
BUNDLE_GEMFILE=Gemfile.mongoid-5.0 bundle update
|
9
10
|
BUNDLE_GEMFILE=Gemfile.mongoid-4.0 bundle update
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bullet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.
|
4
|
+
version: 5.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Huang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -54,6 +54,7 @@ files:
|
|
54
54
|
- Gemfile.mongoid-4.0
|
55
55
|
- Gemfile.mongoid-5.0
|
56
56
|
- Gemfile.mongoid-6.0
|
57
|
+
- Gemfile.mongoid-7.0
|
57
58
|
- Gemfile.rails-4.0
|
58
59
|
- Gemfile.rails-4.1
|
59
60
|
- Gemfile.rails-4.2
|
@@ -84,6 +85,7 @@ files:
|
|
84
85
|
- lib/bullet/mongoid4x.rb
|
85
86
|
- lib/bullet/mongoid5x.rb
|
86
87
|
- lib/bullet/mongoid6x.rb
|
88
|
+
- lib/bullet/mongoid7x.rb
|
87
89
|
- lib/bullet/notification.rb
|
88
90
|
- lib/bullet/notification/base.rb
|
89
91
|
- lib/bullet/notification/counter_cache.rb
|