1. 30 3月, 2015 1 次提交
  2. 27 3月, 2015 1 次提交
  3. 26 3月, 2015 1 次提交
    • J
      Add `config.active_record.warn_on_records_fetched_greater_than` option · 4d6fbe29
      Jason Nochlin 提交于
      When set to an integer, a warning will be logged whenever a result set
      larger than the specified size is returned by a query. Fixes #16463
      
      The warning is outputed a module which is prepended in an initializer,
      so there will be no performance impact if
      `config.active_record.warn_on_records_fetched_greater_than` is not set.
      4d6fbe29
  4. 22 3月, 2015 1 次提交
  5. 18 3月, 2015 1 次提交
  6. 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
  7. 11 3月, 2015 1 次提交
    • S
      Attempt to provide backwards compatible YAML deserialization · afc124c3
      Sean Griffin 提交于
      I should have done this in the first place. We are now serializing an
      explicit version so we can make more careful changes in the future. This
      will load Active Record objects which were serialized in Rails 4.1.
      
      There will be bugs, as YAML serialization was at least partially broken
      back then. There will also be edge cases that we might not be able to
      handle, especially if the type of a column has changed.
      
      In addition, we're passing this as `from_database`, since that is
      required for serialized columns at minimum. All other types were
      serializing the cast value. At a glance, there should be no types for
      which this is a problem.
      
      Finally, dirty checking information will be lost on records serialized
      in 4.1, so no columns will be marked as changed.
      afc124c3
  8. 03 3月, 2015 2 次提交
  9. 02 3月, 2015 3 次提交
  10. 25 2月, 2015 1 次提交
  11. 22 2月, 2015 1 次提交
  12. 06 2月, 2015 2 次提交
  13. 02 2月, 2015 2 次提交
  14. 01 2月, 2015 1 次提交
    • S
      Attribute assignment and type casting has nothing to do with columns · 70ac0729
      Sean Griffin 提交于
      It's finally finished!!!!!!! The reason the Attributes API was kept
      private in 4.2 was due to some publicly visible implementation details.
      It was previously implemented by overloading `columns` and
      `columns_hash`, to make them return column objects which were modified
      with the attribute information.
      
      This meant that those methods LIED! We didn't change the database
      schema. We changed the attribute information on the class. That is
      wrong! It should be the other way around, where schema loading just
      calls the attributes API for you. And now it does!
      
      Yes, this means that there is nothing that happens in automatic schema
      loading that you couldn't manually do yourself. (There's still some
      funky cases where we hit the connection adapter that I need to handle,
      before we can turn off automatic schema detection entirely.)
      
      There were a few weird test failures caused by this that had to be
      fixed. The main source came from the fact that the attribute methods are
      now defined in terms of `attribute_names`, which has a clause like
      `return [] unless table_exists?`. I don't *think* this is an issue,
      since the only place this caused failures were in a fake adapter which
      didn't override `table_exists?`.
      
      Additionally, there were a few cases where tests were failing because a
      migration was run, but the model was not reloaded. I'm not sure why
      these started failing from this change, I might need to clear an
      additional cache in `reload_schema_from_cache`. Again, since this is not
      normal usage, and it's expected that `reset_column_information` will be
      called after the table is modified, I don't think it's a problem.
      
      Still, test failures that were unrelated to the change are worrying, and
      I need to dig into them further.
      
      Finally, I spent a lot of time debugging issues with the mutex used in
      `define_attribute_methods`. I think we can just remove that method
      entirely, and define the attribute methods *manually* in the call to
      `define_attribute`, which would simplify the code *tremendously*.
      
      Ok. now to make this damn thing public, and work on moving it up to
      Active Model.
      70ac0729
  15. 31 1月, 2015 1 次提交
  16. 13 1月, 2015 1 次提交
  17. 10 1月, 2015 1 次提交
  18. 06 1月, 2015 1 次提交
  19. 04 1月, 2015 1 次提交
  20. 30 12月, 2014 3 次提交
  21. 27 12月, 2014 2 次提交
    • S
      Remove `klass` and `arel_table` as a dependency of `PredicateBuilder` · a60770d3
      Sean Griffin 提交于
      This class cares far too much about the internals of other parts of
      Active Record. This is an attempt to break out a meaningful object which
      represents the needs of the predicate builder. I'm not fully satisfied
      with the name, but the general concept is an object which represents a
      table, the associations to/from that table, and the types associated
      with it. Many of these exist at the `ActiveRecord::Base` class level,
      not as properties of the table itself, hence the need for another
      object. Currently it provides these by holding a reference to the class,
      but that will likely change in the future. This allows the predicate
      builder to remain wholy concerned with building predicates.
      
      /cc @mrgilman
      a60770d3
    • S
      Inject the `PredicateBuilder` into the `Relation` instance · 1d6bb776
      Sean Griffin 提交于
      Construction of relations can be a hotspot, we don't want to create one
      of these in the constructor. This also allows us to do more expensive
      things in the predicate builder's constructor, since it's created once
      per AR::Base subclass
      1d6bb776
  22. 23 12月, 2014 1 次提交
  23. 04 12月, 2014 1 次提交
    • Y
      docs, bring back `ActiveRecord::Core` methods in the API. [ci skip] · 9e0dab64
      Yves Senn 提交于
      This `# :nodoc:` had the effect of hiding every method that follows.
      This meant that the API page for `ActiveRecord::Core` only contained
      `configurations` and none of the following methods.
      
      Furthermore this `# :nodoc:` had no effect on `maintain_test_schema`.
      Those `mattr_accessor` inside the `included` block are not picked up
      by rdoc.
      
      /cc @zzak
      9e0dab64
  24. 30 11月, 2014 1 次提交
    • S
      Stop using `Arel::Table.engine` · de239066
      Sean Griffin 提交于
      We never actually make use of it on the table, since we're constructing
      the select manager manually. It looks like if we ever actually were
      grabbing it from the table, we're grossly misusing it since it's meant
      to vary by AR class.
      
      Its existence on `Arel::Table` appears to be purely for convenience
      methods that are never used outside of tests. However, in production
      code it just complicates construction of the tables on the rails side,
      and the plan is to remove it from `Arel::Table` entirely. I'm not
      convinced it needs to live on `SelectManager`, etc either.
      de239066
  25. 15 11月, 2014 1 次提交
    • S
      Reduce the amount of work performed when instantiating AR models · 0f29c216
      Sean Griffin 提交于
      We don't know which attributes will or won't be used, and we don't want
      to create massive bottlenecks at instantiation. Rather than doing *any*
      iteration over types and values, we can lazily instantiate the object.
      
      The lazy attribute hash should not fully implement hash, or subclass
      hash at any point in the future. It is not meant to be a replacement,
      but instead implement its own interface which happens to overlap.
      0f29c216
  26. 01 11月, 2014 2 次提交
    • S
      Treat strings greater than int max value as out of range · e62fff40
      Sean Griffin 提交于
      Sufficiently large integers cause `find` and `find_by` to raise
      `StatementInvalid` instead of `RecordNotFound` or just returning `nil`.
      Given that we can't cast to `nil` for `Integer` like we would with junk
      data for other types, we raise a `RangeError` instead, and rescue in
      places where it would be highly unexpected to get an exception from
      casting.
      
      Fixes #17380
      e62fff40
    • S
      Rename `default_attributes` to `_default_attributes` · 9b9f0197
      Sean Griffin 提交于
      It is internal use only. This is to avoid conflicting with users' method
      names. Fixes #17458
      9b9f0197
  27. 29 10月, 2014 1 次提交
    • X
      let's warn with heredocs · b3bfa361
      Xavier Noria 提交于
      The current style for warning messages without newlines uses
      concatenation of string literals with manual trailing spaces
      where needed.
      
      Heredocs have better readability, and with `squish` we can still
      produce a single line.
      
      This is a similar use case to the one that motivated defining
      `strip_heredoc`, heredocs are super clean.
      b3bfa361
  28. 26 10月, 2014 1 次提交
  29. 29 9月, 2014 2 次提交
    • B
      Isolate access to @associations_cache and @aggregations cache to the... · 9d569585
      Ben Woosley 提交于
      Isolate access to @associations_cache and @aggregations cache to the Associations and Aggregations modules, respectively.
      
      This includes replacing the `association_cache` accessor with a more
      limited `association_cached?` accessor and making `clear_association_cache`
      and `clear_aggregation_cache` private.
      9d569585
    • P
      Reduce allocations when running AR callbacks. · 796cab45
      Pete Higgins 提交于
      Inspired by @tenderlove's work in
      c363fff2, this reduces the number of
      strings allocated when running callbacks for ActiveRecord instances. I
      measured that using this script:
      
      ```
      require 'objspace'
      require 'active_record'
      require 'allocation_tracer'
      
      ActiveRecord::Base.establish_connection adapter: "sqlite3",
                                              database: ":memory:"
      
      ActiveRecord::Base.connection.instance_eval do
        create_table(:articles) { |t| t.string :name }
      end
      
      class Article < ActiveRecord::Base; end
      a = Article.create name: "foo"
      a = Article.find a.id
      
      N = 10
      result = ObjectSpace::AllocationTracer.trace do
        N.times { Article.find a.id }
      end
      
      result.sort.each do |k,v|
        p k => v
      end
      puts "total: #{result.values.map(&:first).inject(:+)}"
      ```
      
      When I run this against master and this branch I get this output:
      
      ```
      pete@balloon:~/projects/rails/activerecord$ git checkout master
      M Gemfile
      Switched to branch 'master'
      pete@balloon:~/projects/rails/activerecord$ bundle exec ruby benchmark_allocation_with_callback_send.rb > allocations_before
      pete@balloon:~/projects/rails/activerecord$ git checkout remove-dynamic-send-on-built-in-callbacks
      M Gemfile
      Switched to branch 'remove-dynamic-send-on-built-in-callbacks'
      pete@balloon:~/projects/rails/activerecord$ bundle exec ruby benchmark_allocation_with_callback_send.rb > allocations_after
      pete@balloon:~/projects/rails/activerecord$ diff allocations_before allocations_after
      39d38
      <
      {["/home/pete/projects/rails/activesupport/lib/active_support/callbacks.rb",
      81]=>[40, 0, 0, 0, 0, 0]}
      42c41
      < total: 630
      ---
      > total: 590
      
      ```
      
      In addition to this, there are two micro-optimizations present:
      
      * Using `block.call if block` vs `yield if block_given?` when the block was being captured already.
      
      ```
      pete@balloon:~/projects$ cat benchmark_block_call_vs_yield.rb
      require 'benchmark/ips'
      
      def block_capture_with_yield &block
        yield if block_given?
      end
      
      def block_capture_with_call &block
        block.call if block
      end
      
      def no_block_capture
        yield if block_given?
      end
      
      Benchmark.ips do |b|
        b.report("block_capture_with_yield") { block_capture_with_yield }
        b.report("block_capture_with_call") { block_capture_with_call }
        b.report("no_block_capture") { no_block_capture }
      end
      pete@balloon:~/projects$ ruby benchmark_block_call_vs_yield.rb
      Calculating -------------------------------------
      block_capture_with_yield
                              124979 i/100ms
      block_capture_with_call
                              138340 i/100ms
          no_block_capture    136827 i/100ms
      -------------------------------------------------
      block_capture_with_yield
                            5703108.9 (±2.4%) i/s -   28495212 in   4.999368s
      block_capture_with_call
                            6840730.5 (±3.6%) i/s -   34169980 in   5.002649s
          no_block_capture  5821141.4 (±2.8%) i/s -   29144151 in   5.010580s
      ```
      
      * Defining and calling methods instead of using send.
      
      ```
      pete@balloon:~/projects$ cat benchmark_method_call_vs_send.rb
      require 'benchmark/ips'
      
      class Foo
        def tacos
          nil
        end
      end
      
      my_foo = Foo.new
      
      Benchmark.ips do |b|
        b.report('send') { my_foo.send('tacos') }
        b.report('call') { my_foo.tacos }
      end
      pete@balloon:~/projects$ ruby benchmark_method_call_vs_send.rb
      Calculating -------------------------------------
                      send     97736 i/100ms
                      call    151142 i/100ms
      -------------------------------------------------
                      send  2683730.3 (±2.8%) i/s -   13487568 in   5.029763s
                      call  8005963.9 (±2.7%) i/s -   40052630 in   5.006604s
      ```
      
      The result of this is making typical ActiveRecord operations slightly faster:
      
      https://gist.github.com/phiggins/e46e51dcc7edb45b5f98
      796cab45
  30. 22 9月, 2014 1 次提交