Commit Graph

89445 Commits

Author SHA1 Message Date
John Hawthorn
578cdf8004 Avoid empty Arrays in ActiveSupport::Callbacks
ActiveSupport::Callbacks often ended up with empty Arrays: on callbacks
without a conditional, and on callback sequences which had no before
and/or after callbacks.
2023-10-21 06:51:03 -07:00
John Hawthorn
6c5a042824 Reduce memory used by ActiveSupport::Callbacks
Previously, callbacks which were shared with subclasses would not share
between them the procs generated in Filters::Before and Filters::After.
This was also lazily generated so would cause memory growth after an
application is booted (and not sharable between workers via CoW).

This was because we would rebuild the objects used to invoke the
callbacks via CallbackChain#compile, so any difference in the callback
chain would result in all of the callback procs being rebuilt.

This commit changes before and after callbacks (but not around!) to be
shared between all subclasses of where it was defined. This is done by
changing Filters::Before and Filters::After to plain classes which
respond to call instead of generating procs (which wasn't strictly
necessary but was easier to implement, and also results in simpler
objects which use less memory). These objects avoid referencing and tied
to a specific callback sequence and so can be memoized and reused.

This has the most impact on applications with many Controllers, and many
callbacks in the ApplicationController (or similar).

I also took this opportunity to merge together all the different forms
of procs generated (halting, halting_and_conditional, conditional,
simple) into one form with if statements. There isn't any significant
performance benefit from the specialization previously being done.
2023-10-20 18:02:33 -07:00
Rafael Mendonça França
7c58911bd8
Merge pull request #49721 from andrewn617/dont-overwrite-broadcast-loggers-broadcast-level-in-bootstrap-rb
Fix issue where `bootstrap.rb` overwrites the `level` of a `BroadcastLogger`'s `broadcasts`
2023-10-20 12:59:24 -04:00
Andrew Novoselac
f212fb8b83 Fix issue where bootstrap.rb overwrites the level of a BroadcastLogger's broadcasts.
In `bootstrap.rb` we set the `Rails.logger.level` to `config.log_level`. But at this point, we may have already set up a `BroadcastLogger` with multiple broadcasts that have different levels. So, calling `level=` on the `BroadcastLogger` will overwrite the level of the individual broadcasts. So instead, let's only set the `Rails.logger.level` if the logger is not a `BroadcastLogger`.
2023-10-20 10:37:54 -04:00
Jean Boussier
f11c6ac45c
Merge pull request #49716 from Shopify/invalid-compressed-cache-entries
Handle outdated Marshal payloads in Cache::Entry with 6.1 cache_format
2023-10-20 15:59:25 +02:00
Ryuta Kamizono
10d880dcd2
Merge pull request #49718 from fatkodima/fix-ordered_options-nested-dig
Fix `OrderedOptions#dig` for array indexes
2023-10-20 19:57:22 +09:00
fatkodima
1b211421cd Fix OrderedOptions#dig for array indexes 2023-10-20 13:44:33 +03:00
Jean Boussier
a6be798e5c Handle outdated Marshal payloads in Cache::Entry with 6.1 cache_format
Ref: https://github.com/rails/rails/issues/48611
Followup: https://github.com/rails/rails/pull/48663

It's the same logic than https://github.com/rails/rails/pull/48663
but now works for the 6.1 cache format.
2023-10-20 10:21:39 +02:00
Rafael Mendonça França
a60a5d0f5b
Merge pull request #49711 from fatkodima/fix-time-travel-helpers-for-separate-object
Fix time travel helpers to work when nested using with separate classes
2023-10-19 21:02:58 -04:00
Rafael Mendonça França
52b85b91ab
Revert "Merge pull request #49710 from zenspider/zenspider/deprecator"
This reverts commit df507240dfc83f120a60b8e2e967d5d96663f67b, reversing
changes made to 9f6b721b1d482ab16d7bdce758fea448bd7ffdbb.

Before using any active support core extension, the user must require
`active_support`.
2023-10-20 00:38:15 +00:00
Aaron Patterson
df507240df
Merge pull request #49710 from zenspider/zenspider/deprecator
Fix activesupport files by requiring missing dependencies
2023-10-19 16:47:18 -07:00
fatkodima
7fd26579c0 Fix time travel helpers to work when nested using with separate classes 2023-10-20 02:46:42 +03:00
Ryan Davis
082e6081a7 Added rails/railtie requires to AS/i18n_railtie.rb and AS/railtie
Not sure this is a valid dependency tho. railtie isn't listed as a
dependency in the gemspec
2023-10-19 16:28:11 -07:00
Ryan Davis
f31c11572b Fixed even more missing requires 2023-10-19 16:27:59 -07:00
Ryan Davis
448cc0d0c3 Fix active_support/*/conversions by requiring missing files 2023-10-19 16:16:08 -07:00
Jonathan Hefner
9f6b721b1d
Merge pull request #49694 from fatkodima/fix-file_store-key-splitting
Fix file cache store `delete_matched` to work on keys longer than allowed filename size
2023-10-19 13:48:01 -05:00
fatkodima
9e9fe7f391 Fix file cache store to split url-encoded keys on encode-sequence boundaries
Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2023-10-19 21:33:02 +03:00
Jonathan Hefner
c48dc47ca3 Use RDoc block quote syntax [ci-skip]
This renders the quote in a `<blockquote>` element instead of a `<pre>`
element.
2023-10-19 13:26:56 -05:00
Eileen M. Uchitelle
f915f412c5
Merge pull request #49701 from eileencodes/use-custom-class-for-pending-migrations-connection
Use custom class for pending migrations connection
2023-10-19 13:17:08 -04:00
eileencodes
64f57c2c9d
Use custom class for pending migrations connection
In bensheldon/good_job#1103 it was reported that a connection not
established is being seen when there are multiple configs for an
environment (a multi-db app).

While I think that something is happening where Good Job is accessing
the connection while we're checking for pending migrations, this could
happen in other gems if we're clobbering the connection on
`ActiveRecord::Base` that is needed.

Here we are making a special class to establish connections to the
database. Because the class does not inherit from `Base` and establishes
it's own connection, it won't clobber any existing connections on
`Base`, leaving them in-tact while the app boots.

The reason this wasn't seen in 7.0 is because pending migrations didn't
check all the available configs. Once that was fixed this error
appeared.

I didn't add a test for this because it's really hard to reproduce
without good job and actually booting a server and running a request.

Fixes: #49689
2023-10-19 12:41:53 -04:00
fatkodima
cae5bafbf2
Merge pull request #49700 from akhilgkrishnan/active-job-argument-typo
Typo fix in BigDecimal job arguments warning
2023-10-19 19:21:42 +03:00
Akhil G Krishnan
6eb93332c4 Typo fix in BigDecimal job arguments warning 2023-10-19 21:22:31 +05:30
Rafael Mendonça França
00dfa109d6
Merge pull request #49680 from seanpdoyle/active-record-include-active-model-api
Include `ActiveModel::API` in `ActiveRecord::Base`
2023-10-18 11:47:55 -04:00
Petrik de Heus
6afe7069c6
Merge pull request #49683 from tiramizoo/fix-field-doc [ci-skip]
Fix code example in the field_name method
2023-10-18 15:53:49 +02:00
Wojciech Wnętrzak
e6a096968b
Fix code example in the field_name method 2023-10-18 15:20:57 +02:00
Jean Boussier
8cf424251e
Merge pull request #49674 from Shopify/drop-mutex-m
Drop dependency on `mutex_m`
2023-10-18 14:38:19 +02:00
Jean Boussier
bcdeea5da7 Drop dependency on mutex_m
It used to be stdlib but is being extracted in modern rubies.

Overall its usefulness is dubious. In all cases it is included in
Rails, it's only for the `synchronize` method, but end up exposing
a dozen other useless methods.

In the end just using a Mutex is clearer and simpler.

In some cases we can even get away with a single mutex in a constant.
2023-10-18 14:27:26 +02:00
Sean Doyle
2c57ec6a17 Include ActiveModel::API in ActiveRecord::Base
`ActiveRecord::Base` does not (and has never) inherit from
`ActiveModel::Model`.

`ActiveModel::API` was introduced in as an extraction from
`ActiveModel::Model`. At that time (Sep 15, 2021), it was included back
into `ActiveModel::Model`, but was never included in `ActiveRecord` at
all.

The intent communicated around the introduction of `ActiveModel::API`
stated:

> By moving `ActiveModel::Model`'s implementation to a new
> `ActiveModel::API` we keep a definition of the minimum API to talk with
> Action Pack and Action View.

Active Record is also designed to integrate with Action Pack and Action
View. It already does (and its integration predates `ActiveModel::API`
by more than a decade). It's integration is powered by including and
extending the same set of foundational modules, with some
database-specific overrides.

This commit adds an `include ActiveModel::API` statement to
`ActiveRecord::Base`, then re-structures those overrides to comply with
the new module resolution order.

[c477d95]: c477d95604
2023-10-18 00:21:14 +01:00
Hartley McGuire
633eb5a9f4
Merge pull request #49676 from aitor/patch-1
Update classic_to_zeitwerk_howto.md [ci skip]
2023-10-17 13:20:47 -04:00
Aitor García Rey
4a3e51a840
Update classic_to_zeitwerk_howto.md
Some typos were fixed on the Zeitwerk migration guide.
2023-10-17 18:54:58 +02:00
Ryuta Kamizono
ae6fa7a048
Merge pull request #49667 from akhilgkrishnan/add-description-for-error-highlight
Add description for error_highlight gem
2023-10-17 18:25:24 +09:00
Akhil G Krishnan
7349b110ae Add description for error_highlight gem 2023-10-17 13:53:10 +05:30
Jonathan Hefner
c139e52ced
Merge pull request #49666 from skipkayhil/hm-fix-error-highlight-spacing
Fix extra blank line when no error_highlight
2023-10-16 23:55:22 -05:00
Hartley McGuire
b62c1ac2ec
Fix extra blank line when no error_highlight
A new condition was recently [added][1] to exclude error_highlight from
the Gemfile when the Ruby version is 3.2 or greater. However, this
change leads to an extra blank line after `gem "spring"` on Ruby 3.2+.
This could also happen to new apps generated on Rubies < 3.1, but my
guess is that is less common.

This commit fixes the issue by moving the extra blank line into the
condition.

[1]: d7b395145c644434b1c2be07ef334ea5cb643b75
2023-10-16 23:55:24 -04:00
Yasuo Honda
196696e4cc
Merge pull request #49663 from yahonda/psych_5111
Bump psych to 5.1.1.1
2023-10-17 09:10:37 +09:00
Yasuo Honda
e9106d0b20 Bump psych to 5.1.1.1
This commit addresses action_controller_gem.rb failure by updating psych as follows.
`$ bundle update psych --conservative`

Refer to https://buildkite.com/rails/rails/builds/100884#018b3a84-f1c5-4461-839c-5cfbe26ee001/1092-1125

- Without this commit
```
$ ruby -v
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-linux]
$ cd guides/bug_report_templates
$ ruby action_controller_gem.rb
Fetching gem metadata from https://rubygems.org/...........
... snip ...
Using rails 7.1.1
/home/yahonda/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.3.22/lib/bundler/runtime.rb:308:in `check_for_activated_spec!': You have already activated psych 5.1.0, but your Gemfile requires psych 5.1.1.1. Prepending `bundle exec` to your command may solve this. (Gem::LoadError)
	from /home/yahonda/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.3.22/lib/bundler/runtime.rb:25:in `block in setup'
	from /home/yahonda/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.3.22/lib/bundler/spec_set.rb:155:in `each'
	from /home/yahonda/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.3.22/lib/bundler/spec_set.rb:155:in `each'
	from /home/yahonda/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.3.22/lib/bundler/runtime.rb:24:in `map'
	from /home/yahonda/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.3.22/lib/bundler/runtime.rb:24:in `setup'
	from /home/yahonda/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.3.22/lib/bundler/inline.rb:66:in `block in gemfile'
	from /home/yahonda/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.3.22/lib/bundler/settings.rb:131:in `temporary'
	from /home/yahonda/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.3.22/lib/bundler/inline.rb:50:in `gemfile'
	from action_controller_gem.rb:5:in `<main>'
$
```
2023-10-17 08:44:14 +09:00
fatkodima
e5c9585b4f
Merge pull request #49660 from seanpdoyle/fix-guides-ci
Fix failing linter in `guides/source`
2023-10-17 01:03:36 +03:00
Sean Doyle
8ecbdb3dbc Fix failing linter in guides/source
Fix [Failing CI Lint][]

Adds a missing comma to make an example Ruby block syntactically valid.

[Failing CI Lint]: https://github.com/rails/rails/actions/runs/6539678344/job/17758241844?pr=49486#step:4:12
2023-10-16 23:00:58 +01:00
eileencodes
0b1a6d76ac
[ci skip] Fix shard docs followup
Oops, the ShardRecord needs to be an abstract class and
ApplicationRecord needs to be a primary_abstract_class
2023-10-16 17:09:46 -04:00
Eileen M. Uchitelle
57d82b47f2
Merge pull request #49658 from eileencodes/fix-shard-docs
[ci skip] Fix shard docs
2023-10-16 17:04:32 -04:00
eileencodes
35e0ae4337
[ci skip] Fix shard docs
We never explained how migrations paths work for shards. This fixes that
and also adds the appropriate class setup. You no longer need to set a
`default` shard as of #48353. In addition, `ApplicationRecord` should be
used for the non-sharded db that also serves as the tenant/shard router.
Then shards should get their own connection class since the schema
differs.
2023-10-16 17:02:11 -04:00
Rafael Mendonça França
2872d55a3b
Revert "Add psych to the bug report template"
This reverts commit e4e242685efc74e4bacccd5c5878bc671fd63fb7.

This doesn't solve the problem.
2023-10-16 15:26:13 +00:00
Rafael Mendonça França
e4e242685e
Add psych to the bug report template
With release of psych 5.1.1.1 bundler doesn't know which version to
load.

https://buildkite.com/rails/rails/builds/100852
2023-10-16 14:14:21 +00:00
Rafael Mendonça França
7767b4f76b
Whitespaces 2023-10-16 13:53:40 +00:00
Rafael Mendonça França
3e810adef5
Avoid __method__
Just be explicit about what we are trying to do here.
2023-10-16 13:49:20 +00:00
Rafael Mendonça França
0737765ddf
We don't use :: to denote class methods 2023-10-16 13:44:04 +00:00
Ryuta Kamizono
2e4061666b
Merge pull request #49490 from stevepolitodesign/sp-improve-generator-logging
Improve `Rails::Generators::Actions` logging and debugging
2023-10-16 17:38:03 +09:00
Jonathan Hefner
2c8428c78a
Merge pull request #44666 from jonathanhefner/active_record-use-attribute_registration
Use `ActiveModel::AttributeRegistration` in AR
2023-10-15 16:35:28 -05:00
Jonathan Hefner
e0a55b038f Use ActiveModel::AttributeRegistration in AR
This refactors the `ActiveRecord::Attributes` module to use
`ActiveModel::AttributeRegistration`.  This also replaces the block form
of the `attribute` method (which was support by only Active Record) with
`decorate_attributes` (which is supported by both Active Model and
Active Record).  The block form of the `attribute` method was a private
API, so no deprecation is necessary.
2023-10-15 16:08:35 -05:00
Jonathan Hefner
a8a5ec4d0e
Merge pull request #44665 from jonathanhefner/active_model-attribute-type-decoration
Support Active Model attribute type decoration
2023-10-15 16:07:57 -05:00