1. 21 3月, 2018 1 次提交
  2. 20 3月, 2018 1 次提交
    • D
      Expose foreign key name ignore pattern in configuration · d3fd4e4e
      David Stosik 提交于
      When dumping the database schema, Rails will dump foreign key names only
      if those names were not generate by Rails. Currently this is determined
      by checking if the foreign key name is `fk_rails_` followed by
      a 10-character hash.
      
      At [Cookpad](https://github.com/cookpad), we use
      [Departure](https://github.com/departurerb/departure) (Percona's
      pt-online-schema-change runner for ActiveRecord migrations) to run migrations.
      Often, `pt-osc` will make a copy of a table in order to run a long migration
      without blocking it. In this copy process, foreign keys are copied too,
      but [their name is prefixed with an underscore to prevent name collision
      ](https://www.percona.com/doc/percona-toolkit/LATEST/pt-online-schema-change.html#cmdoption-pt-online-schema-change-alter-foreign-keys-method).
      
      In the process described above, we often end up with a development
      database that contains foreign keys which name starts with `_fk_rails_`.
      That name does not match the ignore pattern, so next time Rails dumps
      the database schema (eg. when running `rake db:migrate`), our
      `db/schema.rb` file ends up containing those unwanted foreign key names.
      This also produces an unwanted git diff that we'd prefer not to commit.
      
      In this PR, I'd like to suggest a way to expose the foreign key name
      ignore pattern to the Rails configuration, so that individual projects
      can decide on a different pattern of foreign keys that will not get
      their names dumped in `schema.rb`.
      d3fd4e4e
  3. 25 1月, 2018 2 次提交
  4. 14 12月, 2017 1 次提交
    • O
      Log call site for all queries · 3876defd
      Olivier Lacan 提交于
      This new ActiveRecord configuration option allows you to easily
      pinpoint what line of application code is triggering SQL queries in the
      development log by appending below each SQL statement log the line of
      Ruby code that triggered it.
      
      It’s useful with N+1 issues, and to locate stray queries.
      
      By default this new option ignores Rails and Ruby code in order to
      surface only callers from your application Ruby code or your gems.
      
      It is enabled on newly generated Rails 5.2 applications and can be
      enabled on existing Rails applications:
      
      ```ruby
      Rails.application.configure do
        # ...
        config.active_record.verbose_query_logs = true
      end
      ```
      
      The `rails app:upgrade` task will also add it to
      `config/development.rb`.
      
      This feature purposely avoids coupling with
      ActiveSupport::BacktraceCleaner since ActiveRecord can be used without
      ActiveRecord. This decision can be reverted in the future to allow more
      configurable backtraces (the exclusion of gem callers for example).
      3876defd
  5. 20 11月, 2017 1 次提交
    • R
      Prevent extra `spawn` to make `klass.all` faster (#29009) · eeaf9cf6
      Ryuta Kamizono 提交于
      These extra `spawn` are called via `klass.all` and `klass.all` is called
      everywhere in the internal. Avoiding the extra `spawn` makes` klass.all`
      30% faster for STI classes.
      
      https://gist.github.com/kamipo/684d03817a8115848cec8e8b079560b7
      
      ```
      Warming up --------------------------------------
             fast relation     4.410k i/100ms
             slow relation     3.334k i/100ms
      Calculating -------------------------------------
             fast relation     47.373k (± 5.2%) i/s -    238.140k in   5.041836s
             slow relation     35.757k (±15.9%) i/s -    176.702k in   5.104625s
      
      Comparison:
             fast relation:    47373.2 i/s
             slow relation:    35756.7 i/s - 1.32x  slower
      ```
      eeaf9cf6
  6. 09 11月, 2017 2 次提交
  7. 24 10月, 2017 1 次提交
  8. 22 8月, 2017 1 次提交
  9. 12 8月, 2017 1 次提交
  10. 04 8月, 2017 2 次提交
  11. 20 7月, 2017 1 次提交
  12. 19 7月, 2017 1 次提交
  13. 17 7月, 2017 1 次提交
  14. 16 7月, 2017 1 次提交
  15. 02 7月, 2017 1 次提交
  16. 01 7月, 2017 1 次提交
  17. 03 6月, 2017 1 次提交
  18. 15 3月, 2017 1 次提交
  19. 15 1月, 2017 1 次提交
  20. 05 1月, 2017 1 次提交
  21. 04 1月, 2017 2 次提交
  22. 31 12月, 2016 1 次提交
  23. 24 12月, 2016 1 次提交
  24. 06 12月, 2016 1 次提交
  25. 04 11月, 2016 1 次提交
    • S
      Don't assign default attributes until after loading schema · 98faa2a6
      Sean Griffin 提交于
      If the call to `.define_attribute_methods` actually ends up loading the
      schema (*very* hard to do, as it requires the object being created
      without `allocate` having been called, but it can be done by manually
      calling `initialize` from inside `marshal_load` if you're crazy), the
      value of `_default_attributes` will change from that call.
      98faa2a6
  26. 31 10月, 2016 1 次提交
  27. 29 10月, 2016 1 次提交
  28. 26 9月, 2016 1 次提交
    • S
      Use xor to avoid allocations in `AR::Core#hash` · a6da7938
      Sean Griffin 提交于
      This is not as good a solution as actually hashing both values, but Ruby
      doesn't expose that capability other than allocating the array. Unless we were
      to do something silly like have a thread local array that is re-used, I don't
      see any other way to do this without allocation. This solution may not be
      perfect, but it should reasonably avoid collisions to the extent that we need.
      a6da7938
  29. 02 9月, 2016 1 次提交
  30. 01 9月, 2016 1 次提交
  31. 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
  32. 28 8月, 2016 1 次提交
  33. 09 8月, 2016 1 次提交
  34. 08 8月, 2016 2 次提交
  35. 07 8月, 2016 1 次提交