forked from flyerhzm/bullet
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update and merge branch 'flyerhzm/master' #osl
* flyerhzm/master: Auto corrected by following Style/DeprecatedHashMethods Reduce object count start? should check enable? Rename to mongoid 5.0.0-pre. Use Travis' container-based infrastructure. Backport the Query-after-Create fix to AR4.1 and AR4.0. Do not report association queries immediately after object creation to require a preload. README: fix typo add note in README that bullet gem must be added after AR and mongoid flyerhzm#222 support mongoid 5.0.0 Removed circular argument reference error Bumping version to 4.14.8 instruct how to skip bullet in controller action compatible with composite_primary_keys gem flyerhzm#214 Bumping version to 4.14.7
- Loading branch information
Showing
21 changed files
with
242 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
source "https://rubygems.org" | ||
|
||
gemspec | ||
|
||
gem 'rails', '~> 4.0.0' | ||
gem 'sqlite3', platforms: [:ruby] | ||
gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby] | ||
gem 'mongoid', '~> 5.0.0.beta', github: 'mongoid' | ||
|
||
gem "rspec" | ||
|
||
gem 'coveralls', require: false | ||
|
||
platforms :rbx do | ||
gem 'rubysl', '~> 2.0' | ||
gem 'rubinius-developer_tools' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
module Bullet | ||
module Mongoid | ||
def self.enable | ||
require 'mongoid' | ||
::Mongoid::Contextual::Mongo.class_eval do | ||
alias_method :origin_first, :first | ||
alias_method :origin_last, :last | ||
alias_method :origin_each, :each | ||
alias_method :origin_eager_load, :eager_load | ||
|
||
def first | ||
result = origin_first | ||
Bullet::Detector::NPlusOneQuery.add_impossible_object(result) if result | ||
result | ||
end | ||
|
||
def last | ||
result = origin_last | ||
Bullet::Detector::NPlusOneQuery.add_impossible_object(result) if result | ||
result | ||
end | ||
|
||
def each(&block) | ||
records = view.map{ |doc| ::Mongoid::Factory.from_db(klass, doc) } | ||
if records.length > 1 | ||
Bullet::Detector::NPlusOneQuery.add_possible_objects(records) | ||
elsif records.size == 1 | ||
Bullet::Detector::NPlusOneQuery.add_impossible_object(records.first) | ||
end | ||
origin_each(&block) | ||
end | ||
|
||
def eager_load(docs) | ||
associations = criteria.inclusions.map(&:name) | ||
docs.each do |doc| | ||
Bullet::Detector::NPlusOneQuery.add_object_associations(doc, associations) | ||
end | ||
Bullet::Detector::UnusedEagerLoading.add_eager_loadings(docs, associations) | ||
origin_eager_load(docs) | ||
end | ||
end | ||
|
||
::Mongoid::Relations::Accessors.class_eval do | ||
alias_method :origin_get_relation, :get_relation | ||
|
||
def get_relation(name, metadata, object, reload = false) | ||
result = origin_get_relation(name, metadata, object, reload) | ||
if metadata.macro !~ /embed/ | ||
Bullet::Detector::NPlusOneQuery.call_association(self, name) | ||
end | ||
result | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.