1. 24 12月, 2016 1 次提交
  2. 14 9月, 2016 1 次提交
  3. 08 8月, 2016 1 次提交
    • X
      code gardening: removes redundant selfs · a9dc4545
      Xavier Noria 提交于
      A few have been left for aesthetic reasons, but have made a pass
      and removed most of them.
      
      Note that if the method `foo` returns an array, `foo << 1`
      is a regular push, nothing to do with assignments, so
      no self required.
      a9dc4545
  4. 07 8月, 2016 1 次提交
  5. 08 3月, 2016 1 次提交
  6. 23 1月, 2016 1 次提交
    • A
      Eliminate instance level writers for class accessors · 4642d68d
      Aaron Patterson 提交于
      Instance level writers can have an impact on how the Active Model /
      Record objects are saved.  Specifically, they can be used to bypass
      validations.  This is a problem if mass assignment protection is
      disabled and specific attributes are passed to the constructor.
      
      CVE-2016-0753
      4642d68d
  7. 12 1月, 2016 1 次提交
    • M
      Skip the STI condition when evaluating a default scope · 5c6d3653
      Matthew Draper 提交于
      Given a default_scope on a parent of the current class, where that
      parent is not the base class, the parent's STI condition would become
      attached to the evaluated default scope, and then override the child's
      own STI condition.
      
      Instead, we can treat the STI condition as though it is a default scope,
      and skip it in this situation: the scope will be merged into the base
      relation, which already contains the correct STI condition.
      
      Fixes #22426.
      5c6d3653
  8. 25 10月, 2015 1 次提交
  9. 14 10月, 2015 1 次提交
    • Y
      applies new doc guidelines to Active Record. · 428d47ad
      Yves Senn 提交于
      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
      428d47ad
  10. 07 9月, 2015 2 次提交
    • G
      PERF: Don't create a Relation when it is not needed. · 69de09c5
      Guo Xiang Tan 提交于
      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 "f1f0a3f8"
        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
      ```
      69de09c5
    • G
      Cache check if `default_scope` has been overridden. · 52b2ab9e
      Guo Xiang Tan 提交于
      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: 'f1f0a3f8'
        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
      ```
      52b2ab9e
  11. 16 4月, 2015 1 次提交
  12. 01 4月, 2015 1 次提交
  13. 12 3月, 2015 1 次提交
    • B
      Isolate access to .default_scopes in ActiveRecord::Scoping::Default · c1deb81c
      Ben Woosley 提交于
      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.
      c1deb81c
  14. 07 3月, 2014 2 次提交
  15. 22 2月, 2014 1 次提交
  16. 01 9月, 2013 1 次提交
  17. 02 7月, 2013 2 次提交
  18. 09 4月, 2013 2 次提交
  19. 07 4月, 2013 1 次提交
  20. 24 3月, 2013 1 次提交
  21. 29 1月, 2013 1 次提交
  22. 30 10月, 2012 1 次提交
  23. 29 10月, 2012 1 次提交
  24. 22 9月, 2012 1 次提交
  25. 03 8月, 2012 2 次提交
  26. 02 7月, 2012 1 次提交
  27. 16 6月, 2012 1 次提交
  28. 25 4月, 2012 2 次提交
  29. 11 4月, 2012 1 次提交
  30. 22 3月, 2012 1 次提交
    • J
      Deprecate eager-evaluated scopes. · 0a12a5f8
      Jon Leighton 提交于
      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
      0a12a5f8
  31. 29 12月, 2011 1 次提交
    • J
      Support configuration on ActiveRecord::Model. · 93c1f11c
      Jon Leighton 提交于
      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.
      93c1f11c
  32. 18 12月, 2011 1 次提交
  33. 16 12月, 2011 1 次提交