1. 10 10月, 2018 1 次提交
    • E
      Add allocations to template renderer subscription · e8c1be4a
      Eileen Uchitelle 提交于
      This PR adds the allocations to the instrumentation for template and
      partial rendering.
      
      Before:
      
      ```
        Rendering posts/new.html.erb within layouts/application
        Rendered posts/_form.html.erb (9.7ms)
        Rendered posts/new.html.erb within layouts/application (10.9ms)
      Completed 200 OK in 902ms (Views: 890.8ms | ActiveRecord: 0.8ms)
      ```
      
      After:
      
      ```
        Rendering posts/new.html.erb within layouts/application
        Rendered posts/_form.html.erb (Duration: 7.1ms | Allocations: 6004)
        Rendered posts/new.html.erb within layouts/application (Duration: 8.3ms | Allocations: 6654)
      Completed 200 OK in 858ms (Views: 848.4ms | ActiveRecord: 0.4ms | Allocations: 1539564)
      ```
      e8c1be4a
  2. 03 10月, 2018 1 次提交
  3. 29 9月, 2018 1 次提交
    • Y
      Add `Style/RedundantFreeze` to remove redudant `.freeze` · aa3dcabd
      Yasuo Honda 提交于
      Since Rails 6.0 will support Ruby 2.4.1 or higher
      `# frozen_string_literal: true` magic comment is enough to make string object frozen.
      This magic comment is enabled by `Style/FrozenStringLiteralComment` cop.
      
      * Exclude these files not to auto correct false positive `Regexp#freeze`
       - 'actionpack/lib/action_dispatch/journey/router/utils.rb'
       - 'activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb'
      
      It has been fixed by https://github.com/rubocop-hq/rubocop/pull/6333
      Once the newer version of RuboCop released and available at Code Climate these exclude entries should be removed.
      
      * Replace `String#freeze` with `String#-@` manually if explicit frozen string objects are required
      
       - 'actionpack/test/controller/test_case_test.rb'
       - 'activemodel/test/cases/type/string_test.rb'
       - 'activesupport/lib/active_support/core_ext/string/strip.rb'
       - 'activesupport/test/core_ext/string_ext_test.rb'
       - 'railties/test/generators/actions_test.rb'
      aa3dcabd
  4. 27 9月, 2018 1 次提交
  5. 23 9月, 2018 1 次提交
    • Y
      Enable `Performance/UnfreezeString` cop · 1b86d901
      yuuji.yaginuma 提交于
      In Ruby 2.3 or later, `String#+@` is available and `+@` is faster than `dup`.
      
      ```ruby
      # frozen_string_literal: true
      
      require "bundler/inline"
      
      gemfile(true) do
        source "https://rubygems.org"
      
        gem "benchmark-ips"
      end
      
      Benchmark.ips do |x|
        x.report('+@') { +"" }
        x.report('dup') { "".dup }
        x.compare!
      end
      ```
      
      ```
      $ ruby -v benchmark.rb
      ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
      Warming up --------------------------------------
                        +@   282.289k i/100ms
                       dup   187.638k i/100ms
      Calculating -------------------------------------
                        +@      6.775M (± 3.6%) i/s -     33.875M in   5.006253s
                       dup      3.320M (± 2.2%) i/s -     16.700M in   5.032125s
      
      Comparison:
                        +@:  6775299.3 i/s
                       dup:  3320400.7 i/s - 2.04x  slower
      
      ```
      1b86d901
  6. 14 9月, 2018 1 次提交
  7. 13 9月, 2018 1 次提交
  8. 04 9月, 2018 1 次提交
    • A
      Update documentation to ActionController::ConditionalGet · 8634b468
      Anatoly Mikhaylov 提交于
      Two implemented but undocumented features are to help indicate that cache is fresh for 3 hours, and it may continue to be served stale for up to an additional 60 seconds to parallel requests for the same resource or up to 5 minutes while errors are being returned back while the initial synchronous revalidation is attempted.
      8634b468
  9. 01 9月, 2018 1 次提交
    • S
      Faster permitted_scalar_filter · daa3565a
      schneems 提交于
      When running with code triage and derailed benchmarks and focusing on this file:
      
      Before
      
           16199  /Users/rschneeman/Documents/projects/rails/actionpack/lib/action_controller/metal/strong_parameters.r
      
      After
      
            2280  /Users/rschneeman/Documents/projects/rails/actionpack/lib/action_controller/metal/strong_parameters.rb
      daa3565a
  10. 31 8月, 2018 1 次提交
  11. 28 8月, 2018 1 次提交
    • S
      Call block to #redirect_to in controller context (#33735) · 1353610f
      speckins 提交于
      * Call block to #redirect_to in controller context
      
      The documentation for ActionController::Redirecting states that a Proc
      argument "will be executed in the controller's context."  However,
      unless #instance_eval is used (removed in 6b3ad0ca), that statement is
      false for procs defined outside of the controller instance.
      
      This commit restores the documented behavior.
      
      Fixes #33731.
      
      * Move test proc into a constant in another class
      
      Per @rafaelfranca's suggestion.
      
      [Steven Peckins + Rafael Mendonça França]
      1353610f
  12. 27 8月, 2018 1 次提交
  13. 25 8月, 2018 3 次提交
  14. 23 8月, 2018 1 次提交
    • M
      Use string lengths instead of regexp to extract path · eb68fec3
      Matthew Draper 提交于
      The regexp was introduced in 186ac4cd,
      and looks cosmetic. While they should be functionally identical in
      theory, in practice, case insensitive (but preserving) filesystems can
      give results that are differently-cased from the pattern we supplied.
      
      I don't know how to force the filesystem to do the surprising thing,
      even when running in an environment that _could_, so no new test.
      eb68fec3
  15. 18 8月, 2018 1 次提交
  16. 15 8月, 2018 1 次提交
    • B
      Fix rubocop offenses · ea37ccdd
      bogdanvlviv 提交于
      - Layout/TrailingWhitespace
      
      ```
      actionpack/lib/action_controller/metal/request_forgery_protection.rb:49:4:
      C: Layout/TrailingWhitespace: Trailing whitespace detected.
        #
         ^
      ```
      
      Related to c3787494
      
      - Performance/StartWith
      
      ```
      tasks/release.rb:108:44: C: Performance/StartWith:
      Use String#start_with? instead of a regex match anchored to the beginning of the string.
            header += "*   No changes.\n\n\n" if current_contents =~ /\A##/
      ```
      ea37ccdd
  17. 10 8月, 2018 1 次提交
    • E
      Conditionally use `helper_method` in Flash concern · 34326af1
      Eric Anderson 提交于
      I was attempting to use the `flash` functionality in a `Metal`
      controller. When including the `flash` concern I received the following
      error:
      
          NoMethodError: undefined method `helper_method'....
      
      Either:
      
      - `AbstractController::Helpers` should be a dependency of
        `ActionController::Flash`
      - `ActionController::Flash` should not require the existence of
        `AbstractController::Helpers`.
      
      Since my use case (set a flash and redirect) has no need for the helper
      method and that is a common use case, making the dependency conditional
      seemed the better option.
      
      NOTE: This is similar to issue #21067 only the error is within Rails
      itself while that issue had the error within Devise.
      34326af1
  18. 31 7月, 2018 1 次提交
    • P
      Raises exception when respond_to called multiple times in incompatible way · 84e8b350
      Patrick Toomey 提交于
      Nesting respond_to calls can lead to unexpected behavior, so it should be
      avoided. Currently, the first respond_to format match sets the content-type
      for the resulting response. But, if a nested respond_to occurs, it is possible
      to match on a different format. For example:
      
          respond_to do |outer_type|
            outer_type.js do
              respond_to do |inner_type|
                inner_type.html { render body: "HTML" }
              end
            end
          end
      
      Browsers will often include */* in their Accept headers. In the above example,
      such a request would result in the outer_type.js match setting the content-
      type of the response to text/javascript, while the inner_type.html match will
      cause the actual response to return "HTML".
      
      This change tries to minimize potential breakage by only raising an exception
      if the nested respond_to calls are in conflict with each other. So, something
      like the following example would not raise an exception:
      
          respond_to do |outer_type|
            outer_type.js do
              respond_to do |inner_type|
                inner_type.js { render body: "JS" }
              end
            end
          end
      
      While the above is nested, it doesn't affect the content-type of the response.
      84e8b350
  19. 24 7月, 2018 2 次提交
  20. 22 7月, 2018 1 次提交
  21. 21 7月, 2018 2 次提交
  22. 20 7月, 2018 1 次提交
  23. 13 7月, 2018 1 次提交
    • E
      e4e1b620 broke `to_param` handling: · 48b6bacb
      Edouard CHIN 提交于
      - There was an issue inside controller tests where order params were not respected, the reason
        was because we were calling `Hash#to_query` which sorts the results lexicographically.
        1e4e1b62 fixed that issue by not using `to_query` but instead a utility function provided by rack.
      - However with the fix came another issue where it's now no longer possible to do this
      
        ```
         post :foo, params: { user: User.first }
      
         # Prior to the patch the controller will receive { "user" => "1" }
         # Whereas now you get { "user": "#<User: ...>" }
        ```
      
        The fix in this PR is to modify `Hash#to_query` to sort only when it
        doesn't contain an array structure that looks something like "bar[]"
      
        Ref https://github.com/rails/rails/pull/33341#issuecomment-404039396
      48b6bacb
  24. 20 6月, 2018 1 次提交
    • K
      Convert hashes into parameters (#33076) · 716f2e09
      Kevin Sjöberg 提交于
      * Convert hashes into parameters
      
      Ensure `ActionController::Parameters#transform_values` and
      `ActionController::Parameters#transform_values!` converts hashes into
      parameters.
      
      * fixup! Convert hashes into parameters
      
      [Rafael Mendonça França + Kevin Sjöberg]
      716f2e09
  25. 14 6月, 2018 1 次提交
    • D
      Add support for more HTTP cache controls · c94a0075
      Daniel Schierbeck 提交于
      From <https://tools.ietf.org/html/rfc5861>:
      
      > The stale-if-error HTTP Cache-Control extension allows a cache to
      > return a stale response when an error -- e.g., a 500 Internal Server
      > Error, a network segment, or DNS failure -- is encountered, rather
      > than returning a "hard" error.  This improves availability.
      >
      > The stale-while-revalidate HTTP Cache-Control extension allows a
      > cache to immediately return a stale response while it revalidates it
      > in the background, thereby hiding latency (both in the network and on
      > the server) from clients.
      
      These are useful, fully standardized parts of the HTTP protocol with
      widespread support among CDN vendors. Supporting them will make it
      easier to utilize reverse proxies and CDNs from Rails.
      c94a0075
  26. 08 6月, 2018 1 次提交
  27. 31 5月, 2018 1 次提交
  28. 27 5月, 2018 1 次提交
  29. 19 5月, 2018 1 次提交
    • J
      Speed up xor_byte_strings by 70% · 8b10a941
      Jeremy Evans 提交于
      Benchmark:
      
      ```ruby
      require 'benchmark'
      require 'benchmark/ips'
      require 'securerandom'
      
      def xor_byte_strings(s1, s2) # :doc:
        s2_bytes = s2.bytes
        s1.each_byte.with_index { |c1, i| s2_bytes[i] ^= c1 }
        s2_bytes.pack("C*")
      end
      
      def xor_byte_strings_new(s1, s2) # :doc:
        s2 = s2.dup
        size = s1.bytesize
        i = 0
        while i < size
          s2.setbyte(i, s1.getbyte(i) ^ s2.getbyte(i))
          i += 1
        end
        s2
      end
      
      s1 = SecureRandom.random_bytes(32)
      s2 = SecureRandom.random_bytes(32)
      
      Benchmark.ips do |x|
        x.report("current"){xor_byte_strings(s1, s2)}
        x.report("new"){xor_byte_strings_new(s1, s2)}
        x.compare!
      end
      
      100000.times do |i|
        s3 = SecureRandom.random_bytes(32)
        s4 = SecureRandom.random_bytes(32)
        raise unless xor_byte_strings(s3, s4) == xor_byte_strings_new(s3, s4)
      end
      ```
      
      Results on ruby 2.5.1:
      
      ```
      Warming up --------------------------------------
                   current     6.519k i/100ms
                       new    10.508k i/100ms
      Calculating -------------------------------------
                   current     84.723k (_ 0.4%) i/s -    423.735k in   5.001456s
                       new    145.871k (_ 0.3%) i/s -    735.560k in   5.042606s
      
      Comparison:
                       new:   145870.6 i/s
                   current:    84723.4 i/s - 1.72x  slower
      ```
      8b10a941
  30. 18 5月, 2018 1 次提交
  31. 01 5月, 2018 2 次提交
  32. 21 4月, 2018 1 次提交
    • E
      Reset RAW_POST_DATA between test requests · 7a8d9649
      Eugene Kenny 提交于
      `RAW_POST_DATA` is derived from the `rack.input` header, which changes
      with each test request. It needs to be cleared in `scrub_env!`, or all
      requests within the same test will see the value from the first request.
      7a8d9649
  33. 20 4月, 2018 1 次提交
  34. 17 4月, 2018 1 次提交
    • S
      Fixes StrongParameters permit! to work with nested arrays · e539f2d5
      Steve Hull 提交于
      `permit!` is intended to mark all instances of `ActionController::Parameters` as permitted, however nested arrays of params were not being marked permitted because the method did shallow iteration.
      This fixes that by flattening the array before calling `permit!` on all each item.
      e539f2d5
  35. 09 4月, 2018 1 次提交