aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/scoping/default.rb
Commit message (Collapse)AuthorAgeFilesLines
* Do not omit parentheses [ci skip]Ryuta Kamizono2015-10-251-1/+1
|
* applies new doc guidelines to Active Record.Yves Senn2015-10-141-3/+3
| | | | | | | | | | | | | | | | | | | The focus of this change is to make the API more accessible. References to method and classes should be linked to make it easy to navigate around. This patch makes exzessiv use of `rdoc-ref:` to provide more readable docs. This makes it possible to document `ActiveRecord::Base#save` even though the method is within a separate module `ActiveRecord::Persistence`. The goal here is to bring the API closer to the actual code that you would write. This commit only deals with Active Record. The other gems will be updated accordingly but in different commits. The pass through Active Record is not completely finished yet. A follow up commit will change the spots I haven't yet had the time to update. /cc @fxn
* Merge pull request #21522 from tgxworld/scope_perfRafael Mendonça França2015-09-071-1/+8
|\ | | | | PERF: Scope performance.
| * Cache check if `default_scope` has been overridden.Guo Xiang Tan2015-09-071-1/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Benchmark Script: ``` begin require 'bundler/inline' rescue LoadError => e $stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler' raise e end gemfile(true) do source 'https://rubygems.org' # gem 'rails', github: 'rails/rails', ref: 'f1f0a3f8d99aef8aacfa81ceac3880dcac03ca06' gem 'rails', path: '~/rails' gem 'arel', github: 'rails/arel', branch: 'master' gem 'rack', github: 'rack/rack', branch: 'master' gem 'sass' gem 'sprockets-rails', github: 'rails/sprockets-rails', branch: 'master' gem 'sprockets', github: 'rails/sprockets', branch: 'master' gem 'pg' gem 'benchmark-ips' end require 'active_record' require 'benchmark/ips' ActiveRecord::Base.establish_connection('postgres://postgres@localhost:5432/rubybench') ActiveRecord::Migration.verbose = false ActiveRecord::Schema.define do create_table :users, force: true do |t| t.string :name, :email t.timestamps null: false end end class User < ActiveRecord::Base; end attributes = { name: "Lorem ipsum dolor sit amet, consectetur adipiscing elit.", email: "foobar@email.com", } 1000.times { User.create!(attributes) } Benchmark.ips(5, 3) do |x| x.report('where with hash') { User.where(name: "Lorem ipsum dolor sit amet, consectetur adipiscing elit.") } x.report('where with string') { User.where("users.name = ?", "Lorem ipsum dolor sit amet, consectetur adipiscing elit.") } x.compare! end key = if RUBY_VERSION < '2.2' :total_allocated_object else :total_allocated_objects end before = GC.stat[key] User.where(name: "Lorem ipsum dolor sit amet, consectetur adipiscing elit.") after = GC.stat[key] puts "Total Allocated Object: #{after - before}" ``` Stackprof output truncated. ``` TOTAL (pct) SAMPLES (pct) FRAME 52 (10.6%) 10 (2.0%) ActiveRecord::Scoping::Default::ClassMethods#build_default_scope ``` Before: ``` Calculating ------------------------------------- where with hash 2.789k i/100ms where with string 4.407k i/100ms ------------------------------------------------- where with hash 29.170k (± 1.9%) i/s - 147.817k where with string 46.954k (± 2.7%) i/s - 237.978k Comparison: where with string: 46954.3 i/s where with hash: 29169.9 i/s - 1.61x slower Total Allocated Object: 85 Calculating ------------------------------------- all 16.773k i/100ms ------------------------------------------------- all 186.102k (± 3.6%) i/s - 939.288k ``` After: ``` Calculating ------------------------------------- where with hash 3.014k i/100ms where with string 4.623k i/100ms ------------------------------------------------- where with hash 31.524k (± 1.3%) i/s - 159.742k where with string 49.948k (± 2.3%) i/s - 249.642k Comparison: where with string: 49948.3 i/s where with hash: 31524.3 i/s - 1.58x slower Total Allocated Object: 84 Calculating ------------------------------------- all 20.139k i/100ms ------------------------------------------------- all 227.860k (± 2.5%) i/s - 1.148M ```
* | PERF: Don't create a Relation when it is not needed.Guo Xiang Tan2015-09-071-1/+2
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Benchmark script used: ``` begin require 'bundler/inline' rescue LoadError => e $stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler' raise e end gemfile(true) do source 'https://rubygems.org' gem 'rails', path: '~/rails' # master against ref "f1f0a3f8d99aef8aacfa81ceac3880dcac03ca06" gem 'arel', github: 'rails/arel', branch: 'master' gem 'rack', github: 'rack/rack', branch: 'master' gem 'sass' gem 'sprockets-rails', github: 'rails/sprockets-rails', branch: 'master' gem 'sprockets', github: 'rails/sprockets', branch: 'master' gem 'pg' gem 'benchmark-ips' end require 'active_record' require 'benchmark/ips' ActiveRecord::Base.establish_connection('postgres://postgres@localhost:5432/rubybench') ActiveRecord::Migration.verbose = false ActiveRecord::Schema.define do create_table :users, force: true do |t| t.string :name, :email t.timestamps null: false end end class User < ActiveRecord::Base; end attributes = { name: "Lorem ipsum dolor sit amet, consectetur adipiscing elit.", email: "foobar@email.com", } 1000.times { User.create!(attributes) } Benchmark.ips(5, 3) do |x| x.report('all') { User.all } end key = if RUBY_VERSION < '2.2' :total_allocated_object else :total_allocated_objects end before = GC.stat[key] User.where(name: "Lorem ipsum dolor sit amet, consectetur adipiscing elit.") after = GC.stat[key] puts "Total Allocated Object: #{after - before}" ``` Before: ``` Calculating ------------------------------------- all 17.569k i/100ms ------------------------------------------------- all 190.854k (± 3.3%) i/s - 966.295k Total Allocated Object: 85 ``` After: ``` Calculating ------------------------------------- all 22.237k i/100ms ------------------------------------------------- all 262.715k (± 5.5%) i/s - 1.312M Total Allocated Object: 80 ```
* Prevent duplicating `where` clauses when model is extended from an abstract ↵Mehmet Emin İNAÇ2015-04-151-0/+1
| | | | | | | | | | class Fixes #19528 fix for mysql2 test better test
* Fix eager loading association using default_scope for finder methods.Santosh Wadghule2015-03-311-1/+1
| | | | | | - Eager loading was not working for the default_scope (class method) for 'find' & 'find_by' methods. - Fixed these by adding a new check 'respond_to?(:default_scope)'.
* Isolate access to .default_scopes in ActiveRecord::Scoping::DefaultBen Woosley2015-03-121-0/+5
| | | | | | | | | | | Instead use .scope_attributes? consistently in ActiveRecord to check whether there are attributes currently associated with the scope. Move the implementation of .scope_attributes? and .scope_attributes to ActiveRecord::Scoping because they don't particularly have to do specifically with Named scopes and their only dependency, in the case of .scope_attributes?, and only caller, in the case of .scope_attributes is contained in Scoping.
* Merge pull request #14154 from al2o3cr/issue12770Aaron Patterson2014-03-271-3/+3
|\ | | | | Pass a base relation to build_default_scope when joining
| * Pass a base relation to build_default_scope when joiningMatt Jones2014-02-211-3/+3
| | | | | | | | | | This allows the default scope to be built using the current table alias. Resolves #12770
* | fix typo app -> alldmathieu2014-03-071-1/+1
| | | | | | | | Thank you @bquorning
* | unscope doesn't remove only the default_scope, but all of them.dmathieu2014-03-071-4/+5
|/ | | | | [ci-skip] Closes rails/rails#14294
* Don't need to check if the scope respond to callRafael Mendonça França + Kassio Borges2013-08-311-5/+1
| | | | | We are checking this when defining the default scope and raising an ArgumentError
* calling default_scope without a proc will raise ArgumentErrorNeeraj Singh2013-07-021-3/+2
| | | | Calling default_scope without a proc will now raise `ArgumentError`.
* Removed deprecated method default_scopes?Neeraj Singh2013-07-011-8/+0
|
* Delegating the value getter and setters in the ScopeRegistry to thewangjohn2013-04-081-2/+2
| | | | current ScopeRegister object.
* Grouping thread locals in the ActiveRecord scopes so that thewangjohn2013-04-081-2/+2
| | | | | current_scope and ignore_default_scope locals are brought together under a registry object.
* Deprecate ActiveRecord#Base.default_scopes?Agis-2013-04-061-1/+10
| | | | See #10107.
* unscoped works with named scope [ci skip]Neeraj Singh2013-03-231-8/+0
| | | | | Update comment to reflect that unscoped works with named scope even when named scope is using without block form
* Refactor to use each_key, remove extra spacesCarlos Antonio da Silva2013-01-281-3/+1
|
* Make caller attribute in deprecation methods optionalAlexey Gaziev2012-10-301-2/+1
|
* Provide a call stack for deprecation warnings where needed.Nikita Afanasenko2012-10-291-1/+2
| | | | It's sometimes hard to quickly find where deprecated call was performed, especially in case of migrating between Rails versions. So this is an attempt to improve the call stack part of the warning message by providing caller explicitly.
* update AR::Scoping documentation [ci skip]Francesco Rodriguez2012-09-211-26/+29
|
* load active_support/deprecation in active_support/railsXavier Noria2012-08-021-1/+0
|
* load active_support/concern in active_support/railsXavier Noria2012-08-021-1/+0
|
* remove :nodoc: of AR::Scoping#unscoped [ci skip]Francesco Rodriguez2012-07-011-4/+4
|
* Simplify AR configuration code.Jon Leighton2012-06-151-1/+1
| | | | | Get rid of ActiveModel::Configuration, make better use of ActiveSupport::Concern + class_attribute, etc.
* extract to active_record_deprecated_findersJon Leighton2012-04-251-6/+5
|
* giving a hash to default scope should not be deprecated (well, not for this ↵Jon Leighton2012-04-251-1/+1
| | | | reason)
* Corrected grammatical errors in schema_dumper and scoping/defaultdcurtis2012-04-101-1/+1
|
* Deprecate eager-evaluated scopes.Jon Leighton2012-03-211-10/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Don't use this: scope :red, where(color: 'red') default_scope where(color: 'red') Use this: scope :red, -> { where(color: 'red') } default_scope { where(color: 'red') } The former has numerous issues. It is a common newbie gotcha to do the following: scope :recent, where(published_at: Time.now - 2.weeks) Or a more subtle variant: scope :recent, -> { where(published_at: Time.now - 2.weeks) } scope :recent_red, recent.where(color: 'red') Eager scopes are also very complex to implement within Active Record, and there are still bugs. For example, the following does not do what you expect: scope :remove_conditions, except(:where) where(...).remove_conditions # => still has conditions
* Support configuration on ActiveRecord::Model.Jon Leighton2011-12-281-1/+1
| | | | | | | | | | | | | | | The problem: We need to be able to specify configuration in a way that can be inherited to models that include ActiveRecord::Model. So it is no longer sufficient to put 'top level' config on ActiveRecord::Base, but we do want configuration specified on ActiveRecord::Base and descendants to continue to work. So we need something like class_attribute that can be defined on a module but that is inherited when ActiveRecord::Model is included. The solution: added ActiveModel::Configuration module which provides a config_attribute macro. It's a bit specific hence I am not putting this in Active Support or making it a 'public API' at present.
* Improve doc for ActiveRecord::Base.unscoped.Hendy Tanata2011-12-181-6/+8
|
* Move DefaultScope and NamedScope under ScopingJon Leighton2011-12-151-0/+140