Commit Graph

79365 Commits

Author SHA1 Message Date
Ryuta Kamizono 2994c4ba00 Use released redis-namespace instead of master branch
https://rubygems.org/gems/redis-namespace/versions/1.8.1
2021-02-22 18:49:24 +09:00
Ryuta Kamizono 5f94ea0812
Merge pull request #41512 from abhaynikam/fixes-typos-in-doc
Fixes typo in the async query executor documentation added in #41495 [ci skip]
2021-02-22 00:43:18 +09:00
Abhay Nikam f284437955 Fixes typo in the async query executor documentation added in #41495 [ci skip] 2021-02-21 21:09:55 +05:30
Ryuta Kamizono bf594186b8 Address intermittent CI failure due to non-determined sort order
https://buildkite.com/rails/rails/builds/75259#9d1a409b-e2b0-4d0b-a38e-71cfa715c779/1068-1079
2021-02-21 14:09:18 +09:00
Jonathan Hefner 146f0e7847
Merge pull request #41507 from tiramizoo/adjust-webpacker-guide
Adjust application pack in webpacker guide [ci-skip]
2021-02-20 11:03:48 -06:00
Wojciech Wnętrzak 6d0773a468
Adjust application pack in webpacker guide
This is how it looks like when generated in the new app (via Rails 6.1.3)

[ci skip]
2021-02-20 16:54:34 +01:00
David Heinemeier Hansson b90875ebd9
Add ActionController::Live::Buffer#writeln the write a line to the stream with a newline included (#41501)
* 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
2021-02-20 10:02:49 +01:00
Rafael França 4449e83284
Merge pull request #41478 from leequarella/async-finalize-null-session
Add guard for calling `finalize` when NullSession is present
2021-02-19 19:29:41 -05:00
Santiago Bartesaghi ee3cdbecaf
Remove mention to use ActionMailer to receive emails [ci skip] 2021-02-19 14:36:30 -05:00
Eileen M. Uchitelle 9437f6da6b
Merge pull request #41495 from eileencodes/make-executor-configurable
Allow async executor to be configurable
2021-02-19 14:03:34 -05:00
eileencodes d9639a211f
Allow async executor to be configurable
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>
2021-02-19 12:34:57 -05:00
Eileen M. Uchitelle 5b2fb8a6ff
Merge pull request #41499 from Shopify/preload-through-assoc-duplicated-query
Call `run` after preloading records
2021-02-19 12:28:45 -05:00
David Heinemeier Hansson ab8e3d22cb
Extract ActiveStorage::Streaming so your own controllers can use it (#41440)
Extract ActiveStorage::Streaming so your own controller can use it
2021-02-19 15:40:56 +01:00
Jean Boussier 6074c59757 Call `run` after preloading records
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.
2021-02-19 14:49:23 +01:00
Ryuta Kamizono ee7cf8cf75
Merge pull request #41328 from kamipo/avoid-leading-_-from-reserved-options
Allow new syntax for `enum` to avoid leading `_` from reserved options
2021-02-19 15:01:46 +09:00
Ryuta Kamizono 0618d2d84a Allow new syntax for `enum` to avoid leading `_` from reserved options
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
```
2021-02-19 14:43:40 +09:00
Rafael França bc9a4c51a7
Merge pull request #41493 from radar/redirect-back
Add redirect_back directive to Rails 5.0 -> 5.1 upgrade guide
2021-02-18 18:37:10 -05:00
Ryan Bigg c9955d3d03 Add redirect_back directive to Rails 5.0 -> 5.1 upgrade guide 2021-02-19 08:39:18 +11:00
David Heinemeier Hansson 90049a4107
Add send_stream to do for dynamic streams what send_data does for static files (#41488) 2021-02-18 22:35:36 +01:00
Rafael França b8d5279f17
Merge pull request #41475 from Yegorov/add-uncountable
Add `uncountable?` method to ActiveModel::Name
2021-02-18 16:02:34 -05:00
Lee Quarella 601e3d0c4f Remove `finalize` from NullSession
`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.
2021-02-18 15:08:13 -05:00
Lee Quarella 3694e16335 Add `finalize` to NullSession so it quacks like a Session 2021-02-18 07:28:13 -05:00
Ryuta Kamizono 50b5371001
Merge pull request #41483 from 97jaz/schema-dumper-infinite-date
Fix schema dumper for infinite dates in PostgreSQL
2021-02-18 18:05:40 +09:00
Ryuta Kamizono 2cdd608f83 Remove no-op `Relation::WhereClauseFactory` constant
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.
2021-02-18 17:26:01 +09:00
Ryuta Kamizono 7b4efda97a Revert "Merge pull request #39759 from kamipo/marshal_load_legacy_ar_object"
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.
2021-02-18 17:13:41 +09:00
Ryuta Kamizono 0e35e670b2 Remove no-op `PredicateBuilder::BaseHandler` constant
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
2021-02-18 17:04:15 +09:00
Ryuta Kamizono eabf569d3e Update the marshalized object fixtures' version from 6.0 to 6.1
It is a blocker to remove no-op constants in the main branch.
2021-02-18 17:04:15 +09:00
Artem Yegorov 89db42b5e1
Add `uncountable?` method to ActiveModel::Name 2021-02-18 09:55:29 +03:00
Rafael Mendonça França 37303ea499
Avoid having to store complex object in the default translation file
This make possible for applications to use the safe mode of yaml to
load the translations files.

Fixes #41459.
2021-02-18 06:25:56 +00:00
Rafael Mendonça França 561fa1e165
Revert "Add ActiveRecord::Base.connection.with_advisory_lock"
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.
2021-02-17 22:42:02 +00:00
Jon Zeppieri 248b5851fd Fix schema dumper for infinite dates in PostgreSQL
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.
2021-02-17 17:16:06 -05:00
Rafael Mendonça França 8d24c6ba5e
Revert "Merge pull request #41232 from code4me/fix-malformed-packet-master"
This reverts commit 8b3fc5ce30, reversing
changes made to 668c1409f1.

See #41403.
2021-02-17 18:12:36 +00:00
Lee Quarella d21345baf0 Add guard for calling `finalize` on NullSession
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.
2021-02-17 11:25:26 -05:00
Rafael França 89b52a8dd3
Merge pull request #41472 from Shopify/stylesheet-duplicated-media
Fix the duplicated media attribute in stylesheet_link_tag
2021-02-17 10:09:48 -05:00
Rafael França 983a50da87
Merge pull request #41467 from fredplante/improve-rack-test-integration
Improve rack_test integration for system tests
2021-02-17 10:04:40 -05:00
Rafael França 03173c4108
Merge pull request #41468 from p8/update-depraction-warnings-to-7.1
Update Rails version in deprecation and add non-deprecated code
2021-02-17 09:03:51 -05:00
Jean Boussier 1b70109aee Fix the duplicated media attribute in stylesheet_link_tag 2021-02-17 11:34:39 +01:00
Petrik 9ecae8336f Update Rails version in depraction and add non-deprecated code
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.
2021-02-17 09:41:37 +01:00
Ryuta Kamizono d049839e1f alias :without :excluding
Delegation by splat arguments will allocates an extra array.
2021-02-17 15:36:01 +09:00
Ryuta Kamizono c6f0861515 Remove useless branch for the array predicate handler
The array predicate handler don't generate `IN` clause if the values has
only one element.

4ef77ac8de/activerecord/lib/active_record/relation/predicate_builder/array_handler.rb (L22)

Also, I've refactored to avoid extra spawn by `where.not` and directly
mutate `self.where_clause`.
2021-02-17 15:21:03 +09:00
Frédéric Planté adab999e09 Add rack_test driver to System Tests 2021-02-17 00:50:28 +01:00
John Hawthorn 4ef77ac8de
Merge pull request #41463 from jhawthorn/isolated_engine_controller_subclasses
Re-define _routes when not set correctly via inheritance
2021-02-16 13:13:32 -08:00
Kasper Timm Hansen 5b988afda4
Merge pull request #41465 from ashiksp/active_record_query_without
Added ActiveRecord::Relation#without as alias for #excluding.
2021-02-16 21:58:43 +01:00
Eileen M. Uchitelle 48effc7587
Merge pull request #41372 from Shopify/ar-relation-async-query
Implement Relation#load_async to schedule the query on the background thread pool
2021-02-16 15:15:59 -05:00
Josh Goodall 715d6bc4d0 test case to illustrate isolated engine inheritance issue 2021-02-16 11:55:22 -08:00
John Hawthorn d6ca73306c Force _routes to be redefined on re-inclusion
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.
2021-02-16 11:55:22 -08:00
Ashik Salman 3317e9913e Added #without as alias for #excluding. 2021-02-17 01:11:14 +05:30
Rafael França fe912cb1a7
Merge pull request #41464 from p8/deprecate-ivars-locals-in-render-partial
Deprecate render locals to be assigned to instance variables
2021-02-16 14:24:59 -05:00
Petrik 96d72d9b25 Deprecate render locals to be assigned to instance variables
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.
2021-02-16 20:06:59 +01:00
Jean Boussier 2a90104989 Implement Relation#load_async to schedule the query on the background thread pool
This is built on previous async support added to Adapter#select_all.
2021-02-16 17:44:37 +01:00