* Add ActionController::Live::Buffer#writeln to write a line to the stream with a newline included
* Don't add newlines to strings that already have them
This is a followup/alternative to #41406. This change wouldn't work for
GitHub because we intend to implement an executor for each database and
use the database configuration to set the `min_threads` and
`max_threads` for each one.
The changes here borrow from #41406 by implementing an
`Concurrent::ImmediateExecutor` by default. Otherwise applications have
the option of having one global thread pool that is used by all connections
or a thread pool for each connection. A global thread pool can set with
`config.active_record.async_query_executor = :global_thread_pool`. This
will create a single `Concurrent::ThreadPoolExecutor` for applications
to utilize. By default the concurrency is 4, but it can be changed for the
`global_thread_pool` by setting `global_executor_concurrency` to another
number. If applications want to use a thread pool per database
connection they can set `config.active_record.async_query_executor =
:multi_thread_pool`. This will create a `Concurrent::ThreadPoolExecutor`
for each database connection and set the `min_threads` and `max_threads`
by their configuration values or the defaults.
I've also moved the async tests out of the adapter test and into their
own tests and added tests for all the new functionality. This change
would allow us at GitHub to control threads per database and per
writer/reader or other apps to use one global executor. The immediate
executor allows apps to no-op by default.
Took the immediate executor idea from Jean's PR.
Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
Ref: https://github.com/rails/rails/pull/41385
Otherwise the association isn't marked as loaded, and a ThroughAssociation
might perform the same query uselessly.
`already_loaded?` also has to be made lazy, because #41285
made it so that alls the preloaders are instiated together before being ran.
Unlike other features built on Attribute API, reserved options for
`enum` has leading `_`.
* `_prefix`/`_suffix`: #19813, #20999
* `_scopes`: #34605
* `_default`: #39820
That is due to `enum` takes one hash argument only, which contains both
enum definitions and reserved options.
I propose new syntax for `enum` to avoid leading `_` from reserved
options, by allowing `enum(attr_name, ..., **options)` more Attribute
API like syntax.
Before:
```ruby
class Book < ActiveRecord::Base
enum status: [ :proposed, :written ], _prefix: true, _scopes: false
enum cover: [ :hard, :soft ], _suffix: true, _default: :hard
end
```
After:
```ruby
class Book < ActiveRecord::Base
enum :status, [ :proposed, :written ], prefix: true, scopes: false
enum :cover, [ :hard, :soft ], suffix: true, default: :hard
end
```
`finalize_session` should not be able to be called if a session has not
been started, we should never have a `NullSession` when we get there. So
we can remove the guard altogether to help make it obvious if this sort
of thing does happen when it's not supposed to.
That is to prevent the "uninitialized constant" error when loading the
data marshalized by the previous version of Rails (Rails 6.0), it is not
needed for the future version of Rails.
This reverts commit 4fe1452534, reversing
changes made to 0f4258f646.
That is to prevent the "uninitialized constant" error when loading the
data marshalized by the previous version of Rails (Rails 6.0), it is not
needed for the future version of Rails.
See #39759.
I've added the constant alias in that time, but we usually don't
guarantee the marshalized object compatibility.
That is to prevent the "uninitialized constant" error when loading the
data marshalized by the previous version of Rails (Rails 6.0), it is not
needed for the future version of Rails.
See #39611.
I've added the no-op constant in that time, but we usually don't
guarantee the marshalized object compatibility.
This also avoids the "instance variable @future_result not initialized"
warning in the `test_marshal_load_legacy_relation`.
https://buildkite.com/rails/rails/builds/75166#3d7e57df-3679-4fa8-9f17-e1b0533c3ccf/1074-1081
This reverts commit 1ab4dbf8aa.
After speaking with Shopify's resident database experts, they
recommended me to not expose this feature in the public API.
The reason why they don't recommend it, is that this kind of locking
break multiplexing mechanisms like ProxySQL and can decrease the
resiliency of the application.
My original motivation was to remove a monkey patch in our application
and since we are not planning to allow people to use that feature in our
application anymore there is no reason to me expose this locking mechanism
anymore in the framework.
A default value of Float::INFINITY for a date does not round-trip
correctly. It will be correctly loaded as 'infinity'::date, but
when the schema is dumped, it will appear in the schema file as
"Infinity," which then will not load correctly.
This change is based on the fixes for #22396 and #40751, which
address the exact same issue for floats and date-times, respectively.
https://github.com/rails/rails/pull/41372 Added
`ActiveRecord::AsynchronousQueriesTracker::NullSession` which replaced a
use of `nil` in `AsynchronousQueriesTracker`. This commit changes the
`finalize_session` method to match that change from `nil` and properly
handle cases where it is called with a `NullSession` present.
Passing instance variables to `render` will be deprecated in the next
version, which is Rails 7.1.
Also add the non-deprecated implementation, which removes `@?` from the
Regexp, to make removal of the deprecation easier.
This fixes an regression where _routes were set incorrectly when the
inheritance chain went from one route namespace (isolated engine or main
app) to another and then back to the original. Because the url_helpers
module was being cached and was being re-included this was not setting
_routes.
This commit solves the issue by detecting that case and redefining
_routes in that case. We could have always performed the redefinition,
but it's a pretty uncommon case, so we might as well only do it when
necessary.
Rails partial rendering allows assigning instance variables.
For example:
render 'partial', :@name => "Maceo"
This sets @name to "Maceo" on the ActionView::Base object.
The allowed instance variables aren't restricted to the user's defined
instance variables but can also override private Rails variables like
@_assigns, @output_buffer, @_config, and @_default_form_builder.