1. 13 5月, 2020 1 次提交
    • J
      Avoid confliting Kernel-named scopes on Relation · 1b773bca
      John Hawthorn 提交于
      A previous change made singleton methods eagerly define their relation
      methods if it shared a name with a method on Kernel. This caused issues
      with a few methods which were both defined on Kernel and on
      AcitveRecord::Relation.
      
      This commit avoids defining the method if it exists on AR::Relation.
      1b773bca
  2. 12 5月, 2020 1 次提交
  3. 10 5月, 2020 7 次提交
  4. 09 5月, 2020 2 次提交
  5. 08 5月, 2020 1 次提交
  6. 07 5月, 2020 5 次提交
  7. 06 5月, 2020 5 次提交
  8. 05 5月, 2020 6 次提交
  9. 04 5月, 2020 1 次提交
  10. 03 5月, 2020 4 次提交
  11. 02 5月, 2020 5 次提交
    • R
      Fix `minimum` and `maximum` on non numeric column · 767edafc
      Ryuta Kamizono 提交于
      I supposed all aggregation functions will return numeric result in
      #39039, but that assumption was incorrect for `minimum` and `maximum`,
      if an aggregated column is non numeric type.
      
      I've restored type casting aggregated result for `minimum` and `maximum`.
      
      Fixes #39110.
      767edafc
    • R
      Deprecate passing a column to `type_cast` · 92360e9e
      Ryuta Kamizono 提交于
      The type information for type casting is entirely separated to type
      object, so if anyone does passing a column to `type_cast` in Rails 6,
      they are likely doing something wrong. See the comment for more details:
      
      https://github.com/rails/rails/blob/28d815b89487ce4001a3f6f0ab684e6f9c017ed0/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb#L33-L42
      
      This also deprecates passing legacy binds (an array of `[column, value]`
      which is 4.2 style format) to query methods on connection. That legacy
      format was kept for backward compatibility, instead of that, I've
      supported casted binds format (an array of casted values), it is easier
      to construct binds than existing two binds format.
      92360e9e
    • R
      7669dc21
    • E
      Perf: Improve performance of where when using an array of values · 72fd0bae
      eileencodes 提交于
      A coworker at GitHub found a few months back that if we used
      `santitize_sql` over `where` when we knew the values going into `where`
      it was a lot faster than `where`.
      
      This PR adds a new Arel node type called `HomogenousIn` that will be
      used when Rails knows the values are all homogenous and can therefore
      pick a faster codepath. This new codepath skips some of the required
      processing by `where` to make `wheres` with homogenous arrays faster
      without requiring the application author to know when to use which query
      type.
      
      Using our benchmark code:
      
      ```ruby
      ids = (1..1000).each.map do |n|
        Post.create!.id
      end
      
      Benchmark.ips do |x|
        x.report("where with ids") do
          Post.where(id: ids).to_a
        end
      
        x.report("where with sanitize") do
          Post.where(ActiveRecord::Base.sanitize_sql(["id IN (?)", ids])).to_a
        end
      
        x.compare!
      end
      ```
      
      Before this PR comparing where with a list of IDs to santitize sql:
      
      ```
      Warming up --------------------------------------
            where with ids    11.000  i/100ms
       where with sanitize    17.000  i/100ms
      
      Calculating -------------------------------------
            where with ids    115.733  (± 4.3%) i/s -    583.000  in   5.045828s
       where with sanitize    174.231  (± 4.0%) i/s -    884.000  in   5.081495s
      
      Comparison:
       where with sanitize:      174.2 i/s
            where with ids:      115.7 i/s - 1.51x  slower
      ```
      
      After this PR comparing where with a list of IDs to santitize sql:
      
      ```
      Warming up --------------------------------------
            where with ids    16.000  i/100ms
       where with sanitize    19.000  i/100ms
      
      Calculating -------------------------------------
            where with ids    158.293  (± 6.3%) i/s -    800.000  in   5.072208s
       where with sanitize    169.141  (± 3.5%) i/s -    855.000  in   5.060878s
      
      Comparison:
       where with sanitize:      169.1 i/s
            where with ids:      158.3 i/s - same-ish: difference falls within error
      ```
      Co-authored-by: NAaron Patterson <aaron.patterson@gmail.com>
      72fd0bae
    • E
      Support query attrs and bind params in dot output · ff8f40e7
      eileencodes 提交于
      ff8f40e7
  12. 01 5月, 2020 2 次提交
    • R
      Remove internal `without_transaction_enrollment` callbacks · 75873d8f
      Ryuta Kamizono 提交于
      I've found the internal `without_transaction_enrollment` callbacks which
      have not been newly used over five years, when I tried to work reverting
      #9068 (https://github.com/rails/rails/pull/36049#issuecomment-487318060).
      
      I think that we will never make that callbacks public, since the
      mechanism of `without_transaction_enrollment` is too implementation
      specific, at least before #9068, records in a transaction had enrolled
      all into the transaction.
      
      That callbacks was introduced at #18936 to make `touch_later` #19324,
      but I think that the internal callbacks is overkill to just make the
      `touch_later` only, and invoking the extra callbacks also have a little
      overhead even if we haven't used that.
      
      So I think we can remove the internal callbacks for now, until we will
      come up with a good use for that callbacks.
      75873d8f
    • J
      Also batch attribute readers and writers · d12418a7
      Jean Boussier 提交于
      d12418a7