Commit Graph

77464 Commits

Author SHA1 Message Date
Ryuta Kamizono
0fb6993f48 Simplify apply_{start,finish}_limit 2020-07-25 09:38:00 +09:00
Eugene Kenny
7556f7c09c
Merge pull request #39808 from jonathanhefner/include_blank-option-label
Add label attribute to <option> from include_blank
2020-07-24 22:04:27 +01:00
Jonathan Hefner
e6950a332a Add label attribute to <option> from include_blank
The `:include_blank` option of various `<select>`-related helpers causes
an `<option>` element with no content to be rendered.  However, the
[HTML spec] says that unless an `<option>` element has a `label`
attribute (which must be non-empty), its content must be "Text that is
not inter-element whitespace."

In #24923, this issue was addressed for `select_tag` by adding a `label`
attribute to the `<option>`.  This commit addresses the issue in the
same manner for `FormBuilder#select` and various date / time select
helpers.

[HTML spec]: https://html.spec.whatwg.org/multipage/form-elements.html#the-option-element
2020-07-24 15:45:18 -05:00
Eugene Kenny
27f27fb75a
Merge pull request #39728 from maxgurewitz/fix-compression-reads
prevents raw redis and memcached compression
2020-07-24 20:32:08 +01:00
maxgurewitz
f1fb097a74 prevents raw redis and memcached compression
- Fixes issue where reads with raw: true using redis or memcached cache
store, will compress values on reads.
- Should speed up raw cache reads by preventing unnecessary cpu intensive
operation.
2020-07-24 11:56:43 -07:00
Eugene Kenny
8a4192fa3d
Merge pull request #39916 from composerinteralia/remove-pass-from-build-path
Alter regexp on initialize to avoid extra ast pass
2020-07-24 00:11:03 +01:00
Eileen M. Uchitelle
3a1007b196
Merge pull request #39917 from eileencodes/refactor-process-method
Refactor `process` method
2020-07-23 13:14:17 -04:00
eileencodes
5f63c771f7
Refactor process method
Awhile back tenderlove and I worked to improve performance of
integration tests and remove controller tests. The second never
happened, we ended up soft deprecating them but never did that
completely.

Now that we're revisting that work we need a way to override these two
methods in tests so that we can convert tests in Rails to be integration
tests instead of controller tests. Splitting these two concerns into two
methods allows us to overwrite them to work for our needs while
refactoring the test harness code.

These methods are private because they should not be used by an
application or gems, they will be removed when the refactoring has been
completed.

Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
2020-07-23 12:52:21 -04:00
Daniel Colson
4b01bdedd3
Alter regexp on initialize to avoid extra ast pass
Along the same lines as #38901, #39903, and #39914, this commit removes
one pass through the journey ast in an attempt to improve application
boot time.

Before this commit, `Mapper#path` would iterate through the ast to alter
the regex for custom routes. With this commit we move the regex
alterations to initialize, where we were already iterating through the
ast.

The Benchmark for this change is similar to what we have been seeing in
the other PRs.

```
Warming up --------------------------------------
               after    13.121k i/100ms
              before     7.416k i/100ms
Calculating -------------------------------------
               after    128.469k (± 3.1%) i/s -    642.929k in 5.009391s
              before     76.561k (± 1.8%) i/s -    385.632k in 5.038677s

Comparison:
               after:   128469.4 i/s
              before:    76560.8 i/s - 1.68x  (± 0.00) slower

Calculating -------------------------------------
               after   160.000  memsize (     0.000  retained)
                         3.000  objects (     0.000  retained)
                         0.000  strings (     0.000  retained)
              before   360.000  memsize (     0.000  retained)
                         6.000  objects (     0.000  retained)
                         0.000  strings (     0.000  retained)

Comparison:
               after:        160 allocated
              before:        360 allocated - 2.25x more
```
2020-07-23 11:51:08 -04:00
Ryuta Kamizono
43b83955a2 Use arel_table directly instead of newly created table 2020-07-23 21:18:16 +09:00
Ryuta Kamizono
3af558e991
Merge pull request #39881 from kamipo/arel_attribute_normalization
Move Arel attribute normalization into `arel_table`
2020-07-23 15:32:59 +09:00
Ryuta Kamizono
1a70f34c75 Deprecate arel_attribute internal API which is no longer used
Use `arel_table` directly instead.
2020-07-23 12:58:18 +09:00
Ryuta Kamizono
f0de4734d6
Merge pull request #39903 from composerinteralia/fewer-passes-through-ast
Consolidate passes through path ast
2020-07-23 08:18:33 +09:00
Daniel Colson
6a2adeb394
Consolidate passes through path ast
Along the same lines as https://github.com/rails/rails/pull/38901,
this commit makes a small performance enhancement by iterating through
the ast once instead of twice when initializing a Mapping.

This stemmed from work to improve the boot time of an application with
3500+ routes. This patch only shaves off about 70ms from our boot time,
and about 25000 allocations, but every little bit counts!

Benchmark
---

```rb

require "bundler/inline"

gemfile(true) do
  source "https://rubygems.org"

  git_source(:github) { |repo| "https://github.com/#{repo}.git" }

  # Activate the gem you are reporting the issue against.
  gem "rails", path: "/Users/daniel/Desktop/oss/rails/rails"
  gem "benchmark-ips"
  gem "benchmark-memory", require: "benchmark/memory"
end

require "action_controller/railtie"

class TestApp < Rails::Application
  config.root = __dir__
  config.hosts << "example.org"
  config.session_store :cookie_store, key: "cookie_store_key"
  secrets.secret_key_base = "secret_key_base"

  config.logger = Logger.new($stdout)
  Rails.logger = config.logger

  routes.draw do
    get("/*wildcard", to: "controller#index")
  end
end
```

With the benchmarking code inserted into Mapper#initialize:

```rb
after = -> {
  path_params = []
  wildcard_options = {}
  ast.each do |node|
    if node.symbol?
      path_params << node.to_sym
    elsif node.star? && formatted != false
      # Add a constraint for wildcard route to make it non-greedy and match the
      # optional format part of the route by default.
      wildcard_options[node.name.to_sym] ||= /.+?/
    end
  end

  wildcard_options.merge(options)
}

before = -> {
  path_params = ast.find_all(&:symbol?).map(&:to_sym)

  add_wildcard_options(options, formatted, ast)
}

puts "IPS"

Benchmark.ips do |x|
  x.report("before") { before.call }
  x.report("after") { after.call }
  x.compare!
end

puts "MEMORY"

Benchmark.memory do |x|
  x.report("before") { before.call }
  x.report("after") { after.call }
  x.compare!
end
```

The results are:

```
IPS
Warming up --------------------------------------
              before    14.352k i/100ms
               after    30.852k i/100ms
Calculating -------------------------------------
              before    135.675k (± 3.7%) i/s -    688.896k in   5.084368s
               after    288.126k (± 3.3%) i/s -      1.450M in   5.038072s

Comparison:
               after:   288126.4 i/s
              before:   135675.1 i/s - 2.12x  (± 0.00) slower

MEMORY
Calculating -------------------------------------
              before   360.000  memsize (     0.000  retained)
                         7.000  objects (     0.000  retained)
                         0.000  strings (     0.000  retained)
               after   200.000  memsize (     0.000  retained)
                         4.000  objects (     0.000  retained)
                         0.000  strings (     0.000  retained)

comparison:
               after:        200 allocated
              before:        360 allocated - 1.80x more  end
```
2020-07-22 18:57:40 -04:00
Jonathan Hefner
ef4cb3995e
Merge pull request #39904 from mehagar/i18n_root
Fix minor typos in i18n docs [ci-skip]
2020-07-22 08:26:56 -05:00
Michael Hagar
15bb1d59c8 fix minor typos 2020-07-22 08:01:10 -05:00
Ryuta Kamizono
98ddee2b6e
Merge pull request #39895 from abhaynikam/document_default_enum_option
Added documentation for _default option added to ActiveRecord::Enum [ci skip]
2020-07-22 17:51:31 +09:00
Ryuta Kamizono
6ffc813150
Merge pull request #39902 from tgxworld/fix_enum_respects_attribute_override
Fix enum losing attribute type cast.
2020-07-22 17:31:29 +09:00
Guo Xiang Tan
1d41526ba8
Fix enum losing attribute type cast. 2020-07-22 16:16:21 +08:00
Mark Haussmann
71c8a89edd
Sendgrid: prepend X-Original-To header with envelope recipients
Sendgrid, like Mailgun, only passes BCC recipients as a parameter in the original JSON payload.

This PR adds code to prepend the recipients from the Sendgrid payload to the raw_email under the X-Original-To header.

References #38738.
2020-07-21 19:38:38 -04:00
Abhay Nikam
f17c1b7796 Added documentation for _default option added to ActiveRecord::Enum [ci skip] 2020-07-21 21:57:39 +05:30
Ryuta Kamizono
b949e69c5d
Merge pull request #39882 from kamipo/simplify_attribute_type_decoration
Simplify attribute type decoration
2020-07-21 08:47:04 +09:00
Eugene Kenny
57daae230b Assert that DebugExceptions renders HTML by default
This would have made the correct implementation for
894ed87a7e0e1ba36b8ba8f8ead0a871550354e5 more obvious.
2020-07-20 22:37:35 +01:00
Eugene Kenny
fba67f1da1
Merge pull request #38979 from lorennorman/fix-invalid-mime-type
Bugfix for Mime::Type::MimeTypeInvalid handling in ActionDispatch::DebugExceptions
2020-07-20 17:05:23 +01:00
Loren Norman
894ed87a7e Fix InvalidMimeType errors not being caught, with tests.
Co-authored-by: Eugene Kenny <elkenny@gmail.com>
2020-07-20 11:45:57 -04:00
Ryuta Kamizono
e0366022f6 Avoid double time zone converter decoration when user-defined timestamp attribute with implicit type
If type is given as a symbol, it will lookup a fresh type object via
`Type.lookup`, but if type is omitted, `type_for_attribute` will lookup
the database type which is already decorated by `define_attribute`.

To avoid the double decoration, skip extra decoration if its type is
already decorated.
2020-07-20 19:56:01 +09:00
Ryuta Kamizono
d784043d80 Remove internal attribute decoration code
The internal attribute decoration is almost covered by the `attribute`
with block, we don't need to have much code and extra class attribute.
2020-07-20 13:26:25 +09:00
Haroon Ahmed
a653e6cd1d Update wording for cookies, adding information about the http request/response header. Also added the bytes to the cookie size limit 2020-07-19 21:44:30 +01:00
Ryuta Kamizono
c885086bd0 Simplify attribute type decoration
Using `decorate_matching_attribute_type` is overkill to do that.
2020-07-20 02:43:19 +09:00
Ryuta Kamizono
dcf545d20c Revert "Fix test_any in relations_test.rb, which was failing when relations_test.rb is run on its own (it passes when the entire suite is run). This is a hacky fix for a problem I didn't quite get to the bottom of, so I'd welcome a better solution..."
This reverts commit d6289aadce1b8fa93e799500e52f92ce8d159d6f.

`assert_queries` ignores "SCHEMA" queries by default since #36153.
2020-07-20 00:51:34 +09:00
Ryuta Kamizono
1ac40f16c5 Move Arel attribute normalization into arel_table
In Active Record internal, `arel_table` is not directly used but
`arel_attribute` is used, since `arel_table` doesn't normalize an
attribute name as a string, and doesn't resolve attribute aliases.

For the above reason, `arel_attribute` should be used rather than
`arel_table`, but most people directly use `arel_table`, both
`arel_table` and `arel_attribute` are private API though.

Although I'd not recommend using private API, `arel_table` is actually
widely used, and it is also problematic for unscopeable queries and
hash-like relation merging friendly, as I explained at #39863.

To resolve the issue, this change moves Arel attribute normalization
(attribute name as a string, and attribute alias resolution) into
`arel_table`.
2020-07-19 23:41:24 +09:00
Eugene Kenny
c418fb9fe9
Merge pull request #39708 from jonathanhefner/finish_template-goes-last
Ensure principle tasks go before finish_template
2020-07-18 23:49:24 +01:00
Vipul A M
e70023c0d4
Merge pull request #39875 from hennevogel/guides/instrumentation-exceptions
Document how exceptions are handled in instrumentation [ci skip]
2020-07-19 00:35:22 +05:30
Vipul A M
7bfb9276e3
Merge pull request #39872 from fig/fix/typo
fix typo in Active Job exceptions docs [ci skip]
2020-07-18 22:20:00 +05:30
Henne Vogelsang
f5d5cffd90
Document how exceptions are handled in instrumentation 2020-07-18 18:00:35 +02:00
fig
6a4e97c4bb fix typo in Active Job exceptions docs 2020-07-18 11:05:35 +01:00
Eileen M. Uchitelle
7f963b2c95
Merge pull request #39864 from mehagar/duplicating_docs
Fix typos in active support docs [ci-skip]
2020-07-17 15:32:48 -04:00
Michael Hagar
a94d843d12 fix typos in active support docs 2020-07-17 11:25:35 -05:00
Ryuta Kamizono
1ff2abbeb9
Merge pull request #39862 from kamipo/revert_where_with_comparison_operators
Revert "Merge pull request #39613 from kamipo/where_with_custom_operator"
2020-07-17 21:38:46 +09:00
Ryuta Kamizono
da022915d9 Revert "Merge pull request #39613 from kamipo/where_with_custom_operator"
This reverts commit b80645003796690b76aef5c289923db543d84673, reversing
changes made to 8714b359b2c6d3b402cdbaa3f12d2690417e53f4.

Reason: This is not approved from the core team yet...
2020-07-17 21:05:48 +09:00
Eugene Kenny
aa85c4ba0c
Merge pull request #39829 from tgxworld/remove_protect_from_forgery_from_application_controller_template
Remove `protect_from_forgery` in rails plugin template.
2020-07-17 00:12:27 +01:00
Eugene Kenny
9b029331b8
Merge pull request #39861 from vinistock/faster_normalize_path
Switch regex for delete_suffix in normalize_path
2020-07-16 23:33:28 +01:00
Vinicius Stock
4fb78a0b87
Switch regex for delete_suffix in normalize_path 2020-07-16 17:46:38 -04:00
Benoit Tigeot
bcfa51fba6
Link to Action Mailbox's new bug report template [ci skip]
References #39367.
2020-07-15 19:13:09 -04:00
Benoit Tigeot
dbff2df7c2
Add Action Mailbox bug report templates 2020-07-15 11:04:12 -04:00
Ryuta Kamizono
b4ae6d0ec9
Merge pull request #39841 from Madogiwa0124/decorate-skip-sprokets-option-in-guide
Decorated the `--skip-sprockets` like any other.[ci skip]
2020-07-15 12:17:24 +09:00
Ryuta Kamizono
649b77b667
Merge pull request #39840 from PhilCoggins/api_doc_fix
Docs: ActiveRecord::QueryMethods#joins Fixes SQL output

[ci skip]
2020-07-15 12:12:53 +09:00
Chris Oliver
12afb7fb4b
Allow passing URL params to conductor form for inbound emails 2020-07-14 14:02:43 -04:00
eileencodes
6f04ec1ee1
Stop using a singleton for routes
This change ensures we're no longer using a singleton for routes because
we want to change the routing table based on the controller we're
testing. We don't want the routing table to be global for the Action
Pack tests.

Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
2020-07-14 13:46:54 -04:00
Phil Coggins
d54fded536 Docs: ActiveRecord::QueryMethods#joins Fixes SQL output 2020-07-14 07:23:19 -06:00