Commit Graph

90512 Commits

Author SHA1 Message Date
Jean Boussier d839ddb71a Refactor `ActionController::RateLimiting` to use `AS::Cache`
Given that the limiter implementation provided by Kredis is a simple
increment with a limit, all `ActiveSupport::Cache` already provide that
same capability, with a wide range of backing stores, and not just Redis.

This even allow to use SolidCache has a backend if you so desire.

If we feel particularly fancy, we could also accept a more generic
limiter interface to better allow users to swap the implementation
for better algorithms such as leaky-bucket etc.
2024-01-17 15:40:49 +01:00
Jean Boussier b54a287f9d Ensure all Cache store have consistent TTL behavior on increment
Make sure they all increment the counter but don't update the TTL.
2024-01-17 15:40:16 +01:00
Jean Boussier 25b7f64074
Merge pull request #50733 from yash/yk/fix-mysql-escapes-on-default-generated
Fix single quote escapes on default generated MySQL columns
2024-01-17 13:48:03 +01:00
Yash Kapadia 0702c24e7b Fix single quote escapes on default generated MySQL columns
MySQL 5.7.5+ supports generated columns, which can be used to create a column that is computed from an expression. This commit fixes the escaping of the default value for such expressions if a single quote is included.

See the following for more: https://dev.mysql.com/blog-archive/generated-columns-in-mysql-5-7-5/
2024-01-17 07:12:27 -05:00
Jean Boussier a9562e28c4
Merge pull request #50779 from Shopify/debug-ar-time
Fix `ActiveSupport::Notifications.publish_event` to preserve units
2024-01-17 13:07:32 +01:00
Jean Boussier de779f2bf7 Fix `ActiveSupport::Notifications.publish_event` to preserve units
Ref: https://github.com/rails/rails/pull/43502
Fix: https://github.com/rails/rails/pull/50767
Fix: https://github.com/rails/rails/pull/50493

When republishing a an event into a `start, finish` tuple, we need
to convert the timestamps back into seconds.
2024-01-17 12:53:40 +01:00
Yasuo Honda 2fb05958a6
Merge pull request #50756 from Angy-h/getting-started-update-screenshot
Update the screenshot in the section 8.4 of Getting Started with Rails [ci skip]
2024-01-17 18:11:47 +09:00
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
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 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