1. 10 11月, 2014 1 次提交
  2. 08 11月, 2014 2 次提交
  3. 03 11月, 2014 1 次提交
  4. 02 11月, 2014 1 次提交
    • S
      Use bind values for joined tables in where statements · 10f75af9
      Sean Griffin 提交于
      In practical terms, this allows serialized columns and tz aware columns
      to be used in wheres that go through joins, where they previously would
      not behave correctly. Internally, this removes 1/3 of the cases where we
      rely on Arel to perform type casting for us.
      
      There were two non-obvious changes required for this. `update_all` on
      relation was merging its bind values with arel's in the wrong order.
      Additionally, through associations were assuming there would be no bind
      parameters in the preloader (presumably because the where would always
      be part of a join)
      
      [Melanie Gilman & Sean Griffin]
      10f75af9
  5. 29 10月, 2014 2 次提交
    • X
      edit pass over all warnings · e595d91a
      Xavier Noria 提交于
      This patch uniformizes warning messages. I used the most common style
      already present in the code base:
      
      * Capitalize the first word.
      
      * End the message with a full stop.
      
      * "Rails 5" instead of "Rails 5.0".
      
      * Backticks for method names and inline code.
      
      Also, converted a few long strings into the new heredoc convention.
      e595d91a
    • 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
  6. 26 10月, 2014 1 次提交
  7. 23 10月, 2014 1 次提交
  8. 15 10月, 2014 2 次提交
  9. 14 10月, 2014 1 次提交
  10. 06 10月, 2014 1 次提交
  11. 04 10月, 2014 1 次提交
  12. 29 9月, 2014 2 次提交
    • B
      Remove defunct ivars · 588c321e
      Ben Woosley 提交于
      @column_names_with_alias, @dynamic_methods_hash, @time_zone_column_names, and @cached_time_zone
      588c321e
    • 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
  13. 05 9月, 2014 1 次提交
    • G
      Fixed regression with referencing polymorphic assoc in eager-load · a8827cb9
      Godfrey Chan 提交于
      This is cased by 03118bc5 + 9b5d603c. The first commit referenced the undefined
      local variable `column` when it should be using `reflection.type` as the lookup
      key. The second commit changed `build_arel` to not modify the `bind_values` in-
      place so we need to combine the arel's `bind_values` with the relation's when
      building the SQL.
      
      Fixes #16591
      
      Related #15821 / #15892 / 7aeca506
      a8827cb9
  14. 04 9月, 2014 4 次提交
    • S
      Skip StatementCache for eager loaded associations (Fixes #16761) · 4abbdbdf
      Sammy Larbi 提交于
      Eagerly loaded collection and singular associations are ignored by the StatementCache, which causes errors when the queries they generate reference columns that were not eagerly loaded.
      
      This commit skips the creation of the StatementCache as a fix for these scenarios.
      4abbdbdf
    • E
      Always add lambda to scope chain to eliminate branch in eval_scope · 0b6358be
      eileencodes 提交于
      We convert all other scopes to lambda's so it makes sense that we should
      always returns a lambda on a ThroughReflection as well. This eliminates
      the need to check if the scope is a Relation.
      0b6358be
    • E
      Follup to PR #16762 · 8dac5156
      eileencodes 提交于
      Remove chain from parameters, it's no longer needed since chain and i
      are being passed via next_reflection
      
      Change name of `reflection` to `owner_reflection` because of shadow
      variable warning. The last reflection will always be the owner.
      8dac5156
    • Y
      get rid of shadowing warning when running tests AR and railtie tests. · 98318750
      Yves Senn 提交于
      Warning looked like this:
      
      ```
      /Users/senny/Projects/rails/activerecord/lib/active_record/associations/association_scope.rb:142: warning: shadowing outer local variable - reflection
      ```
      98318750
  15. 02 9月, 2014 1 次提交
    • E
      Break conditional branches into separate methods · 8e9e424f
      eileencodes 提交于
      This breaks the two branches of the `if reflection.last` and `else`
      to clearer see where the two methods can be refactored. Eventually
      we hope to remove the need for these separated methods altogether.
      
      Move the first branch outside the loop
      
      This code doesn't need to be in the loop because it it always affects
      the last chain. `get_bind_values` and `add_constraints` must match
      in this context because `get_bind_values` is the caching of `add_constraints`
      
      Use each_cons to remove need for `chain[i + 1]`
      
      The `chain[i + 1]` is confusing because it's not immediately obvious
      what it's trying to achieve. The use of `each_cons` makes it clear
      we need to get the `next_reflection`.
      8e9e424f
  16. 29 8月, 2014 1 次提交
    • G
      Avoid using heredoc for user warnings · 8c52480b
      Godfrey Chan 提交于
      Using heredoc would enforce line wrapping to whatever column width we decided to
      use in the code, making it difficult for the users to read on some consoles.
      
      This does make the source code read slightly worse and a bit more error-prone,
      but this seems like a fair price to pay since the primary purpose for these
      messages are for the users to read and the code will not stick around for too
      long.
      8c52480b
  17. 27 8月, 2014 4 次提交
  18. 20 8月, 2014 1 次提交
  19. 19 8月, 2014 1 次提交
  20. 18 8月, 2014 1 次提交
    • J
      Updating Associations::Preloader docs · 27c9a23e
      Jack Danger Canty 提交于
      Much of the previous documentation introduced features new in 2011. This
      commit refreshes it to provide clearer code examples and spends more
      time describing the normal case (preloaded associations) and less time
      describing the fallback.
      
      [ci skip]
      27c9a23e
  21. 17 8月, 2014 2 次提交
  22. 15 8月, 2014 1 次提交
  23. 05 8月, 2014 1 次提交
  24. 03 8月, 2014 1 次提交
  25. 01 8月, 2014 1 次提交
  26. 31 7月, 2014 2 次提交
    • E
      Refactor join_keys to remove complex conditionals · 377bece6
      eileencodes 提交于
      Pushing conditionals down to through reflection
      
      Only the through association needs the part of this conditional
      that deals with belongs to and polymorphic? so that can be pushed
      down into the ThroughReflection reducing the conditionals.
      
      Remove conditional because we can delegate join keys to source reflection
      
      Remove need for source_macro checking
      
      By adding join_id_for to the other reflections we remove the need
      to cehck against the source_macro and can reduce the conditioanl
      from the original join_id_for(owner)
      
      Using polymorphism instead of testing the source_macro
      
      This case statement in join_association is almost exactly the same
      as the original join_keys code. Testing taht theory by creating a
      new join_dependency_keys(assoc_klass) method.
      
      Refactor join_keys further to be more concise
      
      Fixed format of "#:nodoc:" to "# :nodoc:" where I added them to this
      file.
      377bece6
    • E
      Redefine macro checks for reflections · 8d7dea76
      eileencodes 提交于
      Now that we define the macro on the reflection type we no longer
      need to check `macro == :what` on each type for `belongs_to?` or
      `has_one?` etc. These now default to false unless it's defined
      in the reflection class.
      
      Reuse existing belongs_to? method to check macros
      
      We don't need to do `:belongs_to == macro` anymore becasue we
      have a `belongs_to?` method. I didn't find this being used
      anywhere for `has_one?` or `collection?` since they were already
      fixed.
      8d7dea76
  27. 29 7月, 2014 1 次提交
  28. 28 7月, 2014 1 次提交
    • E
      [ci skip] Fix documentation for @macro and reflection types · bd54e195
      eileencodes 提交于
      Since `@macro` doesn't exist anymore and these reflections are no
      longer AssociationReflections but their own types of reflections
      based on macro I updated the documentation to match the changes I
      made in #16089 and #16198. An `AssociationReflection` that had a
      `@macro` of `:has_many` now is a `HasManyReflection`
      bd54e195