1. 25 3月, 2018 1 次提交
    • E
      Don't unset foreign key when preloading missing record · 0cdeda58
      Eugene Kenny 提交于
      When a belongs to association's target is set, its foreign key is now
      updated to match the new target. This is the correct behaviour when a
      new record is assigned, but not when the existing record is preloaded.
      
      As long as we mark the association as loaded, we can skip setting the
      target when the record is missing and avoid clobbering the foreign key.
      0cdeda58
  2. 04 3月, 2018 1 次提交
  3. 26 2月, 2018 1 次提交
    • R
      Association creation and finding should work consistently (#32048) · 8ff70cad
      Ryuta Kamizono 提交于
      This is an alternative of #29722, and revert of #29601 and a1fcbd97.
      
      Currently, association creation and normal association finding doesn't
      respect `store_full_sti_class`. But eager loading and preloading respect
      the setting. This means that if set `store_full_sti_class = false`
      (`true` by default), eager loading and preloading can not find
      created polymorphic records.
      
      Association creation and finding should work consistently.
      8ff70cad
  4. 23 2月, 2018 1 次提交
    • R
      Use private attr_reader · 6d63b5e4
      Ryuta Kamizono 提交于
      Since #32028, Rails 6 requires Ruby 2.3+.
      No longer needed workaround for Ruby 2.2 "private attribute?" warning.
      6d63b5e4
  5. 29 1月, 2018 1 次提交
    • D
      Avoid extra calls to to_s · 2e8c8d60
      Daniel Colson 提交于
      With #31615 `type_for_attribute` accepts either
      a symbol as well as a string. `has_attribute?` and `attribute_alias`
      also accept either. Since these methods call `to_s` on the argument,
      we no longer need to do that at the call site.
      2e8c8d60
  6. 10 11月, 2017 1 次提交
    • R
      Remove useless preloader classes · de40c45f
      Ryuta Kamizono 提交于
      They are only different by one line of code which doesn't deserve a
      hierarchy of 7 classes.
      
      Closes #31079.
      
      [Ryuta Kamizono & Bogdan Gusiev]
      de40c45f
  7. 08 11月, 2017 1 次提交
  8. 07 11月, 2017 1 次提交
    • R
      Remove useless `associated_records_by_owner` · 3f1695bb
      Ryuta Kamizono 提交于
      `associated_records_by_owner` had returned customizing result before
      calling `associate_records_to_owner` for through association subclasses.
      Since #22115, `associate_records_to_owner` is called in the method and
      not returned owner and result pairs. Removing the method will reduce
      method call and block call nesting.
      3f1695bb
  9. 06 11月, 2017 1 次提交
  10. 26 9月, 2017 1 次提交
    • G
      PERF: Partially recover some performance when preloading. · e03c9066
      Guo Xiang Tan 提交于
      Benchmark Script:
      ```
      require 'active_record'
      require 'benchmark/ips'
      
      ActiveRecord::Base.establish_connection(ENV.fetch('DATABASE_URL'))
      ActiveRecord::Migration.verbose = false
      
      ActiveRecord::Schema.define do
        create_table :users, force: true do |t|
          t.string :name, :email
          t.integer :topic_id
          t.timestamps null: false
        end
      
        create_table :topics, force: true do |t|
          t.string :title
          t.timestamps null: false
        end
      end
      
      attributes = {
        name: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
        email: 'foobar@email.com'
      }
      
      class Topic < ActiveRecord::Base
        has_many :users
      end
      
      class User < ActiveRecord::Base
        belongs_to :topic
      end
      
      100.times do
        User.create!(attributes)
      end
      
      users = User.first(50)
      
      Topic.create!(title: 'This is a topic', users: users)
      
      Benchmark.ips do |x|
        x.config(time: 10, warmup: 5)
      
        x.report("preload") do
          User.includes(:topic).all.to_a
        end
      end
      ```
      
      Before:
      ```
      Calculating -------------------------------------
                   preload    40.000  i/100ms
      -------------------------------------------------
                   preload    407.962  (± 1.5%) i/s -      4.080k
      ```
      
      After:
      ```
      alculating -------------------------------------
                   preload    43.000  i/100ms
      -------------------------------------------------
                   preload    427.567  (± 1.6%) i/s -      4.300k
      ```
      e03c9066
  11. 18 9月, 2017 4 次提交
  12. 11 9月, 2017 1 次提交
    • G
      PERF: Incorrect memoization in `ActiveRecord::Associations::Preloader::Association`. · 32e1e709
      Guo Xiang Tan 提交于
      ```
      require 'active_record'
      require 'benchmark/ips'
      
      ActiveRecord::Base.establish_connection(ENV.fetch('DATABASE_URL'))
      ActiveRecord::Migration.verbose = false
      
      ActiveRecord::Schema.define do
        create_table :users, force: true do |t|
          t.string :name, :email
          t.integer :topic_id
          t.timestamps null: false
        end
      
        create_table :topics, force: true do |t|
          t.string :title
          t.timestamps null: false
        end
      end
      
      attributes = {
        name: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
        email: 'foobar@email.com'
      }
      
      class Topic < ActiveRecord::Base
        has_many :users
      end
      
      class User < ActiveRecord::Base
        belongs_to :topic
      end
      
      100.times do
        User.create!(attributes)
      end
      
      users = User.first(50)
      
      100.times do
        Topic.create!(title: 'This is a topic', users: users)
      end
      
      Benchmark.ips do |x|
        x.config(time: 10, warmup: 5)
      
        x.report("preload") do
          User.includes(:topic).all.to_a
        end
      end
      ```
      
      ```
      Calculating -------------------------------------
                   preload    25.000  i/100ms
      -------------------------------------------------
                   preload    251.772  (± 1.2%) i/s -      2.525k
      ```
      
      ```
      Calculating -------------------------------------
                   preload    26.000  i/100ms
      -------------------------------------------------
                   preload    270.392  (± 1.1%) i/s -      2.704k
      ```
      32e1e709
  13. 05 9月, 2017 1 次提交
  14. 04 9月, 2017 1 次提交
    • R
      Scope in associations should treat nil as `all` · 925e6d56
      Ryuta Kamizono 提交于
      Defined scope treats nil as `all`, but scope in associations isn't so.
      If the result of the scope is nil, most features on associations will be
      broken. It should treat nil as `all` like defined scope.
      
      Fixes #20823.
      925e6d56
  15. 15 8月, 2017 1 次提交
  16. 26 7月, 2017 1 次提交
  17. 20 7月, 2017 1 次提交
  18. 18 7月, 2017 1 次提交
  19. 07 7月, 2017 1 次提交
    • R
      Make preload query to preparable · 452a814c
      Ryuta Kamizono 提交于
      Currently preload query cannot be prepared statements even if
      `prepared_statements: true` due to array handler in predicate builder
      doesn't support making bind params. This makes preload query to
      preparable by don't passing array value if possible.
      452a814c
  20. 04 7月, 2017 2 次提交
  21. 02 7月, 2017 1 次提交
  22. 01 7月, 2017 1 次提交
  23. 30 5月, 2017 1 次提交
  24. 29 10月, 2016 1 次提交
  25. 31 8月, 2016 1 次提交
    • S
      Ensure that inverse associations are set before running callbacks · caa178c1
      Sean Griffin 提交于
      If a parent association was accessed in an `after_find` or
      `after_initialize` callback, it would always end up loading the
      association, and then immediately overwriting the association we just
      loaded. If this occurred in a way that the parent's `current_scope` was
      set to eager load the child, this would result in an infinite loop and
      eventually overflow the stack.
      
      For records that are created with `.new`, we have a mechanism to
      perform an action before the callbacks are run. I've introduced the same
      code path for records created with `instantiate`, and updated all code
      which sets inverse instances on newly loaded associations to use this
      block instead.
      
      Fixes #26320.
      caa178c1
  26. 16 8月, 2016 1 次提交
  27. 07 8月, 2016 1 次提交
  28. 30 7月, 2016 1 次提交
  29. 04 2月, 2016 1 次提交
  30. 21 12月, 2015 1 次提交
    • Y
      Revert "Merge pull request #22486 from methyl/fix-includes-for-groupped-association" · b06f6a1d
      Yves Senn 提交于
      This reverts commit 537ac7d6, reversing
      changes made to 9c9c54ab.
      
      Reason:
      The way we preload associations will change the meaning of GROUP BY
      operations. This is illustrated in the SQL generated by the added
      test (failing on PG):
      
      Association Load:
      D, [2015-12-21T12:26:07.169920 #26969] DEBUG -- :   Post Load (0.7ms)  SELECT "posts".* FROM "posts" LEFT JOIN comments ON comments.post_id = posts.id WHERE "posts"."author_id" = $1 GROUP BY posts.id ORDER BY SUM(comments.tags_count)  [["author_id", 1]]
      
      Preload:
      D, [2015-12-21T12:26:07.128305 #26969] DEBUG -- :   Post Load (1.3ms)  SELECT "posts".* FROM "posts" LEFT JOIN comments ON comments.post_id = posts.id WHERE "posts"."author_id" IN (1, 2, 3) GROUP BY posts.id ORDER BY SUM(comments.tags_count)
      b06f6a1d
  31. 16 12月, 2015 1 次提交
  32. 30 10月, 2015 3 次提交
  33. 29 10月, 2015 1 次提交
  34. 22 10月, 2015 1 次提交