Commit Graph

90558 Commits

Author SHA1 Message Date
Akira Matsuda a71e0aabe3
Merge pull request #46872 from amatsuda/fast_string_to_time_bug
TZ offset minute has to be negated in the Western Hemisphere
2024-01-17 17:55:38 +09:00
Akira Matsuda d10d5aedce
TZ offset minute has to be negated in the Western Hemisphere
When the TZ in the given string contains minus offset, both hour and minute
value has to be negated, but the current code negates hour only.
Hence, for instance in Newfoundland Time Zone (UTC−03:30), it used to return
1 hour advanced value.

Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
2024-01-17 17:25:37 +09:00
Robert Fletcher 929f9fd3fe Fix threading issue with strict locals
Fixes #50774

When the server boots up, 2 threads hit the same `UnboundTemplate`
instance before it has set up `@templates`. Both threads get past the
`unless template = @templates[locals]` check because
`@templates[locals]` isn't set yet. However, with `@write_lock`, one
thread waits while the other one proceeds, setting `@templates` to a
frozen hash. The second thread then gets the write lock and tries to
modify `@templates` but it has been frozen.
2024-01-16 16:27:58 -08:00
Rafael Mendonça França 473fd597f6
Merge pull request #50769 from p8/actiontext/eager-load-with-includes
Use `includes` instead of `eager_load` for `with_all_rich_text`
2024-01-16 18:28:38 -05:00
Rafael Mendonça França 474ee0a014
Merge pull request #50773 from skipkayhil/hm-fix-another-compat-issue
Fix t.references validating options on Rails < 7.1
2024-01-16 18:09:33 -05:00
Hartley McGuire 597b56cde0
Optimize TagBuilder tag generation
Currently there's about a 35% difference between tags generated using
the `TagBuilder` and tags generated by passing a positional argument to
`#tag`.

This commit optimizes `TagBuilder` to reduce that difference down to 13%.

The first change is to perform less hash allocations by not splatting
the options twice in the `TagBuilder` (one at the `tag.a` invocation,
and one at `tag_string`). The extra splat for `tag_string` was moved
into `method_missing` since that is the only other caller of this
private method.

The other change is to only escape the content in `tag_string` if it a
non-empty.

Additionally, a test was tweaked to ensure that passing `options` to a
`self_closing_element` is tested as it was previously not.

Benchmark:

```
require "action_view"
require "benchmark/ips"

class Foo
  include ActionView::Helpers
end

helpers = Foo.new

Benchmark.ips do |x|
  x.report("tag") { helpers.tag("a", href: "foo") }
  x.report("tag_builder") { helpers.tag.a(href: "foo") }
  x.compare!
end
```

Before:

```
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [arm64-darwin22]
Warming up --------------------------------------
                 tag    67.180k i/100ms
         tag_builder    50.267k i/100ms
Calculating -------------------------------------
                 tag    673.064k (± 0.4%) i/s -      3.426M in   5.090520s
         tag_builder    504.971k (± 0.4%) i/s -      2.564M in   5.076842s

Comparison:
                 tag:   673063.7 i/s
         tag_builder:   504971.4 i/s - 1.33x  slower
```

After:

```
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [arm64-darwin22]
Warming up --------------------------------------
                 tag    67.374k i/100ms
         tag_builder    59.702k i/100ms
Calculating -------------------------------------
                 tag    670.837k (± 0.4%) i/s -      3.369M in   5.021714s
         tag_builder    592.727k (± 1.3%) i/s -      2.985M in   5.037088s

Comparison:
                 tag:   670836.6 i/s
         tag_builder:   592726.7 i/s - 1.13x  slower
```

Co-authored-by: Sean Doyle <seanpdoyle@users.noreply.github.com>
2024-01-16 17:51:21 -05:00
Hartley McGuire 327f28b65f
Fix t.references validating options on Rails < 7.1
Option validation was [added][1] for 7.1+ Migration classes, and a
compatibility layer was added to ensure that previous Migration versions
do not have their options validated. However, the `t.references` method
was missing in the compatibility layer which results in pre 7.1
Migrations validating options passed to `t.references`.

This commit fixes the issue by adding t.references to the compatibility
layer.

See also a [similar fix][2] for `add_reference`

[1]: e6da3ebd6c
[2]: 71b4e22301
2024-01-16 17:21:22 -05:00
Petrik 3b49e47ce8 Use `includes` instead of `eager_load` for `with_all_rich_text`
`eager_load` performs a single query using a `LEFT OUTER JOIN` to load
the associations. Loading the associations in a join can result in many
rows that contain redundant data and it performs poorly at scale.

With `includes` a separate query is performed for each association,
unless a join is required by conditions.

Co-authored-by: Rafael Mendonça França <rafael@franca.dev>
2024-01-16 22:06:19 +01:00
Xavier Noria 299900f4e5 Edit pass over the railties CHANGELOG 2024-01-16 20:39:04 +01:00
Aaron Patterson eccaddba5c
Merge pull request #50758 from rails/fix-video-preview-nplus1
Eagerly load preview images (N+1)
2024-01-16 10:44:10 -08:00
Aaron Patterson 7e9b5889cc
update changelog 2024-01-16 09:36:44 -08:00
Aaron Patterson f2f50c904e
Fix N+1 on scope with non-image previews 2024-01-16 09:36:43 -08:00
Xavier Noria cb035bde4e
Merge pull request #50723 from aeroastro/feature/no-file-in-load-path
Ensure only directories exist in Rails default load paths
2024-01-16 17:48:26 +01:00
Jean Boussier 758e6e1a22
Merge pull request #50767 from rporrasluc/fix-db-runtime-calculation
Fix calculation of SQL runtime
2024-01-16 17:21:05 +01:00
Rafael Porras Lucena a88ee05fe0
Fix calculation of SQL runtime 2024-01-16 16:16:41 +01:00
Eugene Kenny 0656787be6
Merge pull request #50764 from eugeneius/syntax_error_proxy_nil_backtrace_locations
Handle nil backtrace_locations in SyntaxErrorProxy
2024-01-16 14:20:13 +00:00
Jean Boussier 4fa50ba38a
Merge pull request #50766 from Shopify/merdernize-method-missing
Modernize method missing implementations
2024-01-16 13:28:39 +01:00
Jean Boussier 946e46ebcc Modernize method missing implementations
`...` is both simpler an more correct since the keyword argument
separation.
2024-01-16 13:17:45 +01:00
Jean Boussier 6a9795d4d2
Merge pull request #50751 from skipkayhil/hm-av-silenceable-start
Add silenced? for Action View Start subscriber
2024-01-16 12:37:14 +01:00
Eugene Kenny 16d1351a93 Handle nil backtrace_locations in SyntaxErrorProxy 2024-01-16 01:05:53 +00:00
Rafael Mendonça França 7266313106
Merge pull request #50466 from skipkayhil/hm-fix-to-symbol-raising-nomethoderror
Add custom ArgumentError for invalid to: values
2024-01-15 17:49:31 -05:00
Rafael Mendonça França 3cae956152
Merge pull request #46191 from yahonda/enable_layout_def_end_alignment
Enable `Layout/DefEndAlignment` cop
2024-01-15 17:47:02 -05:00
Rafael Mendonça França a39332fa45
Remove code duplication and improve message 2024-01-15 22:29:46 +00:00
Hartley McGuire 0821d25d56
Add custom ArgumentError for invalid to: values
Previously, it was theoretically possible to define a route with a
Symbol as a `to:` value (or at least, it would not raise a
`NoMethodError`). However, passing a Symbol broke when `/#/.match?(to)`
was [replaced][1] with `to&.include?("#")` with the assumption that `to`
was always a String.

Instead of restoring the previous error, this commit improves how the
`to:` value is checked so that it raises an `ArgumentError` for any
invalid values. The extra strictness will specifically improve the error
when a Symbol or String that doesn't include a "#" are passed since they
were effectively equivalent to passing a `nil` value, or not specifying
`to:` at all.

[1]: 5726b1d1d7
2024-01-15 22:29:45 +00:00
Rafael Mendonça França cddf163632
Make sure after_routes_loaded hook runs on boot
This hook was only running when routes were reloaded, but not on boot.

The goal was to run any time routes are loaded. This commit fixes it
and adds a test.

Fixes #50720.
2024-01-15 22:26:02 +00:00
Rafael Mendonça França 62972a16c9
Merge pull request #50680 from skipkayhil/hm-fix-legacy-add-reference
Fix add_reference options validated on < 7.1
2024-01-15 16:25:22 -05:00
Aaron Patterson 5f7bbf2925
Update activestorage/test/models/variant_with_record_test.rb
Co-authored-by: Petrik de Heus <petrik@deheus.net>
2024-01-15 13:10:32 -08:00
Hartley McGuire 71b4e22301
Fix add_reference options validated on < 7.1
Option validation was [added][1] for 7.1+ Migration classes, and
a compatibility layer was added to ensure that previous Migration
versions do not have their options validated. However, the add_reference
method was missing in the compatibility layer which results in pre 7.1
Migrations validating options passed to add_reference.

This commit fixes the issue by adding add_reference to the compatibility
layer. In addition to adding add_reference to the "no validation"
compatibility test, the test is refactored to run against each previous
migration version to ensure that they all behave consistently.

[1]: e6da3ebd6c
2024-01-15 20:52:49 +00:00
Rafael Mendonça França af2bbd5f66
Merge pull request #46383 from dmytro-savochkin/fix-activerecord-reload-association-cache
Ensure `reload` sets correct owner for each association (ActiveRecord::Persistence)
2024-01-15 15:48:25 -05:00
Hartley McGuire d255ffd035
Add silenced? for Action View Start subscriber
Previously, the `render_template.action_view` and
`render_layout.action_view` events would always be handled as if they
had subscribers even if the log level of its subscribers result in
nothing being logged. For regular `LogSubscriber`s,
`subscribe_log_level` could be used to optimize these cases but the
Start subscriber is not a subclass of `LogSubscriber`.

This commit implements a `#subscribed?` method for the Start subscriber
so that it can also benefit from the `subscribe_log_level` optimization.
2024-01-15 15:46:24 -05:00
Aaron Patterson 4a18e06864
use assert_operator for better error message 2024-01-15 11:41:30 -08:00
Aaron Patterson 496d761553
Eagerly load preview images
For non-image attachments (like videos), generated representations are
created as a preview_image_attachment instead of as normal variants, and
as a result aren't included in the `with_attached_` scopes. This adds
those preview image attachments to the `includes` of these scopes to
avoid an N+1 when iterating over a collection of attachments and
fetching the key of their representation (variants).

Co-Authored-By: Justin Searls <searls@gmail.com>
2024-01-15 11:41:30 -08:00
Aaron Patterson 3307a73c06
Failing test for #50560
Co-Authored-By: Justin Searls <searls@gmail.com>
2024-01-15 11:41:30 -08:00
Rafael Mendonça França 883b033c4e
Merge pull request #50662 from nubinary/feature/delegated-type-types-introspection
Define a class method to introspect valid delegatable types so they can
2024-01-15 14:04:14 -05:00
Rafael Mendonça França afc7d035d9
Merge pull request #50753 from adrienpoly/remove-deprecated-yarn-check
removes deprecated yarn check in bin/setup
2024-01-15 13:50:19 -05:00
JP Rosevear b3fecab5c0
Merge branch 'main' into feature/delegated-type-types-introspection 2024-01-15 12:46:59 -05:00
Jean Boussier 0496a5f994
Merge pull request #50706 from Shopify/attr-base-class
Handle alternative base classes in `define_attribute_methods`
2024-01-15 17:28:44 +01:00
Jean Boussier 2cd568a5da Handle alternative base classes in `define_attribute_methods`
Ref: d429bfb3b6 (r136670440)
2024-01-15 17:20:56 +01:00
Jean Boussier e59b779a24
Merge pull request #50757 from Shopify/url-config-booleans
Make `schema_dump`, `query_cache`, `replica` and `database_tasks` configurable via `DATABASE_URL`
2024-01-15 15:57:33 +01:00
Jean Boussier 63631e2d5b Make `schema_dump`, `query_cache`, `replica` and `database_tasks` configurable via `DATABASE_URL`
Fix: https://github.com/rails/rails/pull/50745

I went a bit farther and handled all the boolean configs, not just `schema_cache`.

Co-Authored-By: Mike Coutermarsh <coutermarsh.mike@gmail.com>
2024-01-15 15:51:31 +01:00
Jean Boussier fc7befc87a
Merge pull request #50752 from seanpdoyle/issue-49818-changelog
Re-word #49856 CHANGELOG entry [ci skip]
2024-01-15 10:55:48 +01:00
Annaheim.h@gmail.com bd934475b9 [docs] Update Screenshot in "Getting Started with Rails"
Replace the existing screenshot with the output produced in Rails 7. The current screenshot
seems to be captured in a previous version.
2024-01-15 18:43:26 +09:00
Jonathan Hefner 5034b08890
Merge pull request #50742 from r-plus/fix/msgpack-cache-ipaddr
Fix IPAddr prefix information missing when write to cache in msgpack serializer
2024-01-15 00:54:08 -06:00
r-plus 38151711c8 Fix IPAddr prefix information missing when write to cache in msgpack serializer
* Save cache size by omit the prefix if unnecessary

* rename to straightforward naming.

* check the prefix directly instead of inspect

* Remove unused helper method

* add to changelog

Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2024-01-15 00:40:44 -06:00
Takumasa Ochi 23cc9229ff
Ensure only directories exist in Rails default load paths
Previously, some files put under `app` directory would contaminate the load paths.
This commit removes files from the default load paths set up by the Rails framework.

Now, only directories are included as default in the following paths:

* autoload_paths
* autoload_once_paths
* eager_load_paths
* load_paths
2024-01-15 15:04:53 +09:00
Yasuo Honda 5f04fa99dc Enable `Layout/DefEndAlignment` cop
Follow-up #46188

- After reverting the merge commit via #46188

```
$ git revert -m 1 4328d0e160
[enable_layout_def_end_alignment 8445594965] Revert "Merge pull request #46188 from yahonda/follow_up_45081"
 1 file changed, 1 insertion(+), 1 deletion(-)
$ bundle exec rubocop
Inspecting 3041 files
... snip ...
Offenses:

activerecord/test/cases/query_logs_formatter_test.rb:10:5: W: [Correctable] Layout/DefEndAlignment: end at 10, 4 is not aligned with def at 6, 2.
    end
    ^^^

3041 files inspected, 1 offense detected, 1 offense auto-correctable
$
```
2024-01-15 11:00:32 +09:00
Adrien POLY 88e8774844 remove deprecated yarn check 2024-01-14 22:43:46 +01:00
Sean Doyle a93d1e39cc Re-word #49856 CHANGELOG entry
Follow-up to [#49856][]

Replace shell word expansion with full English. In addition to that
change, elaborate on the changes with more detailed explanation.

[#49856]: https://github.com/rails/rails/pull/49856#discussion_r1451634684
2024-01-14 15:18:45 -05:00
Jonathan Hefner 0ecfbe2568
Merge pull request #50749 from Earlopain/changelog-typo
Fix typo in ActiveSupport changelog [ci-skip]
2024-01-14 10:31:12 -06:00
Earlopain 805fa6faf3
Fix typo in ActiveSupport changelog 2024-01-14 14:15:54 +01:00