1. 21 10月, 2015 5 次提交
  2. 20 10月, 2015 9 次提交
  3. 19 10月, 2015 4 次提交
  4. 18 10月, 2015 6 次提交
  5. 17 10月, 2015 9 次提交
  6. 16 10月, 2015 7 次提交
    • J
      `where` raises ArgumentError on unsupported types. · 7663376f
      Jake Worth 提交于
      [#20473]
      7663376f
    • Y
      Merge pull request #21969 from ignatiusreza/remove_readonly_option_doc · b3656076
      Yves Senn 提交于
      Remove mentioned of 'readonly' options in doc for HABTM [ci skip]
      b3656076
    • I
      [ci skip] readonly options has been removed · 15f75193
      Ignatius Reza 提交于
      15f75193
    • A
      drop array allocations when iterating over the hash · 960de47f
      Aaron Patterson 提交于
      `each_with_object` allocates an array for each kv pair.  Switching to
      the slightly more verbose but less allocatey `each_pair` eliminates
      array allocations.  Eliminating this allocation returns AR objects to
      have constant array allocations regardless of the number of columns the
      object has.
      
      Here is test code:
      
      ```ruby
      require 'active_record'
      
      class Topic < ActiveRecord::Base
      end
      
      20.times do |i|
        Process.waitpid fork {
          ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:'
      
          ActiveRecord::Base.connection.instance_eval do
            create_table(:topics) do |t|
              t.string   :title, limit: 250
              t.string   :author_name
              t.string   :author_email_address
              t.string   :parent_title
              t.string   :type
              t.string   :group
              i.times do |j|
                t.string :"aaa#{j}"
              end
              t.timestamps null: true
            end
          end
      
          ObjectSpace::AllocationTracer.setup(%i{type})
      
          Topic.create title: "aaron" # heat cache
      
          result = ObjectSpace::AllocationTracer.trace do
            10.times do |i|
              Topic.create title: "aaron #{i}"
            end
          end
      
          puts "#{Topic.columns.length},#{(result.find { |k,v| k.first == :T_ARRAY }.last.first / 10)}"
        }
      end
      ```
      
      Before this commit:
      
      ```
      9,166
      10,167
      11,168
      12,169
      13,170
      14,171
      15,172
      16,173
      17,174
      18,175
      19,176
      20,177
      21,178
      22,179
      23,180
      24,181
      25,182
      26,183
      27,184
      28,185
      ```
      
      After:
      
      ```
      9,157
      10,157
      11,157
      12,157
      13,157
      14,157
      15,157
      16,157
      17,157
      18,157
      19,157
      20,157
      21,157
      22,157
      23,157
      24,157
      25,157
      26,157
      27,157
      28,157
      ```
      
      Left side is the number of columns, right is the number of allocations
      960de47f
    • R
      Merge pull request #21966 from AnnaErshova/dbreset-edit · 3b610270
      Rafael Mendonça França 提交于
      Clarifies db can be set up from structure.sql as well as from schema.rb
      3b610270
    • A
      Update active_record_migrations.md · 5cde56e1
      Anna Ershova 提交于
      Add 'db/'; corrects structure.rb to structure.sql
      5cde56e1
    • A
      make string allocation constant regardless of column count · 3253185b
      Aaron Patterson 提交于
      deep_dup'ing a hash will dup the keys as well as the values.  Since
      string keys from the source hash will be frozen, and the dup'd objects
      are immediately dup'd and frozen on insert in to the hash, the end user
      will only ever see two frozen strings.  Since the strings are immutable,
      this commit just cheats a little and reuses the immutable strings.
      
      Just to reiterate, before this commit, deep duping a hash that looks
      like this: `{ "foo" => "bar" }` will generate two new instances of
      "foo". One is created when `deep_dup` is called on "foo", and the other
      is created when the newly allocated "foo" string is inserted in to the
      hash.  The user never sees the intermediate "foo", and both copies of
      "foo" that the user *can* access will be frozen, so in this case we just
      reuse the existing frozen key.
      
      The upshot is that after this change, string allocations on AR
      allocations become constant regardless of the number of columns the
      model has.
      
      ```ruby
      require 'active_record'
      
      class Topic < ActiveRecord::Base
      end
      
      20.times do |i|
        Process.waitpid fork {
          ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:'
      
          ActiveRecord::Base.connection.instance_eval do
            create_table(:topics) do |t|
              t.string   :title, limit: 250
              t.string   :author_name
              t.string   :author_email_address
              t.string   :parent_title
              t.string   :type
              t.string   :group
              i.times do |j|
                t.integer :"aaa#{j}"
              end
              t.timestamps null: true
            end
          end
      
          ObjectSpace::AllocationTracer.setup(%i{type})
      
          Topic.create title: "aaron" # heat cache
      
          result = ObjectSpace::AllocationTracer.trace do
            10.times do |i|
              Topic.create title: "aaron #{i}"
            end
          end
      
          puts "#{Topic.columns.length},#{(result.find { |k,v| k.first == :T_STRING }.last.first / 10)}"
        }
      end
      ```
      
      If you run the above script before this commit, the output looks like
      this:
      
      ```
      [aaron@TC rails (master)]$ be ruby -rallocation_tracer test.rb
      9,105
      10,107
      11,109
      12,111
      13,113
      14,115
      15,117
      16,119
      17,121
      18,123
      19,125
      20,127
      21,129
      22,131
      23,133
      24,135
      25,137
      26,139
      27,141
      28,143
      ```
      
      The left column is the number of methods, the right column is the number
      of string allocations.
      
      Running against this commit, the output is:
      
      ```
      [aaron@TC rails (master)]$ be ruby -rallocation_tracer test.rb
      9,87
      10,87
      11,87
      12,87
      13,87
      14,87
      15,87
      16,87
      17,87
      18,87
      19,87
      20,87
      21,87
      22,87
      23,87
      24,87
      25,87
      26,87
      27,87
      28,87
      ```
      
      As you can see, there is now only a constant number of strings
      allocated, regardless of the number of columns the model has.
      3253185b