Commit Graph

91784 Commits

Author SHA1 Message Date
Maximo Mussini
a054307bbc
Improve compatibility between Logger and ActiveSupport::BroadcastLogger
The usage of `dispatch` in all logging methods causes common usages such
as `logger.info` to return an array of loggers, making it unsafe for an
application to upgrade to Rails 7.1.

Returning `nil` is more efficient, and is the default behavior when
using `Logger`.
2024-05-29 22:18:37 +00:00
Xavier Noria
b9f814ad86
Merge pull request #51937 from rails/fxn/nil-uuid
Define Digest::UUID.nil_uuid
2024-05-29 14:50:16 +02:00
Xavier Noria
a7d7e3d884 Define Digest::UUID.nil_uuid 2024-05-29 14:41:30 +02:00
Jean Boussier
d50fc2202d
Merge pull request #51744 from Shopify/result-rows
Index Result rows rather than to convert them into hashes
2024-05-29 08:14:03 +02:00
Jean Boussier
10dfdc5eb1 Index Result rows rather than to convert them into hashes
Using the same benchmark as https://github.com/rails/rails/pull/51726

A significant part of the memory footprint comes from `Result#each`:

```
Total allocated: 4.61 MB (43077 objects)
Total retained: 3.76 MB (27621 objects)

allocated memory by file
-----------------------------------
 391.52 kB  activerecord/lib/active_record/result.rb

retained memory by file
-----------------------------------
 374.40 kB  activerecord/lib/active_record/result.rb
```

Rows are initially stored as arrays, but `Result#each` convert them
to hashes. Depending on how many elements they contain, hashes use
between 2 and 5 times as much memory than arrays.

|    Length |      Hash |     Array |      Diff |
| --------- | --------- | --------- | --------- |
|         1 |       160B |        40B |      -120B |
|         2 |       160B |        40B |      -120B |
|         3 |       160B |        40B |      -120B |
|         4 |       160B |        80B |       -80B |
|         5 |       160B |        80B |       -80B |
|         6 |       160B |        80B |       -80B |
|         7 |       160B |        80B |       -80B |
|         8 |       160B |        80B |       -80B |
|         9 |       464B |       160B |      -304B |
|        10 |       464B |       160B |      -304B |
|        11 |       464B |       160B |      -304B |
|        12 |       464B |       160B |      -304B |
|        13 |       464B |       160B |      -304B |
|        14 |       464B |       160B |      -304B |
|        15 |       464B |       160B |      -304B |
|        16 |       464B |       160B |      -304B |
|        17 |       912B |       160B |      -752B |
|        18 |       912B |       160B |      -752B |
|        19 |       912B |       320B |      -592B |
|        20 |       912B |       320B |      -592B |
|        21 |       912B |       320B |      -592B |
|        22 |       912B |       320B |      -592B |
|        23 |       912B |       320B |      -592B |
|        24 |       912B |       320B |      -592B |
|        25 |       912B |       320B |      -592B |
|        26 |       912B |       320B |      -592B |
|        27 |       912B |       320B |      -592B |
|        28 |       912B |       320B |      -592B |
|        29 |       912B |       320B |      -592B |
|        30 |       912B |       320B |      -592B |
|        31 |       912B |       320B |      -592B |
|        32 |       912B |       320B |      -592B |
|        33 |      1744B |       320B |     -1424B |
|        34 |      1744B |       320B |     -1424B |
|        35 |      1744B |       320B |     -1424B |
|        36 |      1744B |       320B |     -1424B |
|        37 |      1744B |       320B |     -1424B |
|        38 |      1744B |       320B |     -1424B |
|        39 |      1744B |       640B |     -1104B |
|        40 |      1744B |       640B |     -1104B |
|        41 |      1744B |       640B |     -1104B |
|        42 |      1744B |       640B |     -1104B |
|        43 |      1744B |       640B |     -1104B |
|        44 |      1744B |       640B |     -1104B |
|        45 |      1744B |       640B |     -1104B |
|        46 |      1744B |       640B |     -1104B |
|        47 |      1744B |       640B |     -1104B |
|        48 |      1744B |       640B |     -1104B |
|        49 |      1744B |       640B |     -1104B |
|        50 |      1744B |       640B |     -1104B |

Rather than to convert rows into hashes, we can loopkup the column index
into a single Hash common to all rows. To not complexify the code too much,
rather than to pass the row array and the column index, we wrap both into
an `IndexedRow` object, which uses an extra `40B` object, but that's still
less memory even in the worst case.

After:

```
Total allocated: 4.32 MB (43079 objects)
Total retained: 3.65 MB (29725 objects)

allocated memory by file
-----------------------------------
 101.66 kB  activerecord/lib/active_record/result.rb

retained memory by file
-----------------------------------
  84.70 kB  activerecord/lib/active_record/result.rb
```

As for access speed, it's of course a bit slower, but not by much,
it's between `1.5` and `2` times slower, but remains in the 10's of M
iterations per second, so I think this overhead is negligible compared
to all the work needed to access a model attribute.

Also the `LazyAttributeSet` class only access this once, after the
attribute is casted, the resulting value is still stored in a regular
`Hash`.
2024-05-29 07:32:18 +02:00
Rafael Mendonça França
e2ef1d6818
Merge pull request #50828 from akhilgkrishnan/add-example-for-month-field-tag
Add examples for form helper tags [ci skip]
2024-05-28 18:02:40 -04:00
Rafael Mendonça França
e46e56b1f4
Merge pull request #51892 from florin555/fix_pretty_print
Make `pretty_print` behave more similar to `inspect`.
2024-05-28 18:00:40 -04:00
Rafael Mendonça França
93f4b6d7a6
Merge pull request #51930 from justinko/issue-51914
Improve ActionCable's TestCookieJar interface
2024-05-28 16:24:14 -04:00
Justin Ko
24472e01c1
Improve ActionCable TestCookieJar interface
Fixes #51914
2024-05-28 20:09:39 +00:00
Rafael Mendonça França
23151ea1bd
Merge pull request #51934 from jrmhaig/wasm_unsafe_eval
Add CSP mapping for 'wasm-unsafe-eval'
2024-05-28 14:53:10 -04:00
Joe Haig
10dc425e8e
Add CSP mapping for 'wasm-unsafe-eval'
The `'wasm-unsafe-eval'` keyword for the Content Security Policy allows the
loading and execution of WebAssembly modules without the need to allow unsafe
JavaScript execution via `'unsafe-eval'`. A mapping is added so that the symbol
`:wasm_unsafe_evel` can be used for this keyword in the policy configuration in
`config/initializers/content_security_policy.rb`.
2024-05-28 18:39:48 +00:00
Rafael Mendonça França
bcba3f327a
Use docker.io as the default registry for Ruby images
The `registry.docker.com` registry isn't documented and have a delay
when pulling images. The `docker.io` registry is the default registry
for Docker images and is the one used by the Docker CLI.
2024-05-28 18:21:48 +00:00
Rafael Mendonça França
809409ab29
Merge pull request #51925 from zzak/re-51395-proxy_association
Make CollectionProxy#proxy_association public API
2024-05-28 13:39:28 -04:00
Vipul A M
31b7b1eade
Merge pull request #51935 from pdxmike/guides-minor-spelling-update
Guides: Minor Update To Spelling [ci skip]
2024-05-28 21:27:54 +05:30
Mike Hickman
c6df8baf4b Update spelling: Getting Start to Getting Started 2024-05-28 16:01:41 +01:00
Jean Boussier
fae23a37df
Merge pull request #51932 from Shopify/relation-model
Unify `Relation#klass` and `Relation#model`
2024-05-28 15:00:38 +02:00
Xavier Noria
630fc98709 Rewrite unless/else as if/else
I believe it is generally accepted that unless/else is hard to read,
too many negations.
2024-05-28 13:44:13 +02:00
Xavier Noria
2aeb322806 Let's use the delegation to the transaction manager here
`within_new_transaction` is delegated to the transaction manager. Let's remove
this explicit receiver to honor the delegation and for consistency with usage
of the also delegated `current_transaction`.
2024-05-28 13:21:10 +02:00
Jean Boussier
9f901b7350 Unify Relation#klass and Relation#model
One is the alias of the other, and have been so for a very long time.

My issue with this is that `klass` is really a bad name, and it's
very confusing when reading code to see a mix of both names being
used.

There is no point officially deprecating either, but inside
Active Record we should consistently only use one, I chose to
use `model` as it's way more descriptive in my opinion.
2024-05-28 11:24:35 +02:00
Jean Boussier
9ce4d4468e Explictly take a block in Arel add_bind
Fix: https://github.com/rails/rails/issues/51926

This prevent a false positive warning for unused blocks
on Ruby 3.4-dev.
2024-05-28 08:53:30 +02:00
Jean Boussier
407031f8b8
Merge pull request #50396 from Shopify/stricter-relation-delegation
Make the Relation -> Model delegation stricter
2024-05-28 08:47:41 +02:00
Jean Boussier
fd5bd98b34 Make the Relation -> Model delegation stricter
In https://github.com/rails/rails/pull/50395 I noticed lots of
methods are delegated from `Relation` to the model. The intent of
this code is to allow using use defined class methods like scopes.

But because of this autmated delegation it allows calling any
`ActiveRecord::Base` class method on a `Relation`, which in itself
may be desireable, however we very wastefully define the delegator
on the first call, and worse we wrap it with a global scope setter.

This also has led to bugs in the past, like https://github.com/rails/rails/pull/51776

So I think we should be more strict about it.

We can't deprecate this behavior because gems might depend on it, however we
can ban it from Active Record's own test suite to avoid regressions.
2024-05-28 08:13:23 +02:00
zzak
7aa7e1e3e1
Make CollectionProxy#proxy_association public API
Co-authored-by: Petrik <petrik@deheus.net>
2024-05-28 07:47:43 +09:00
Rafael Mendonça França
f6918a5b5d
Merge pull request #51909 from rails/rm-release-notes
Draft of the release notes
2024-05-27 16:39:42 -04:00
Rafael Mendonça França
58883a5f8b
Merge pull request #51371 from theodorton/relation-test-readonly
Add `ActiveRecord::Relation#readonly?`
2024-05-27 16:39:30 -04:00
Rafael Mendonça França
b0efe426e7
Edit pass on 7.2 release notes 2024-05-27 19:53:04 +00:00
Theodor Tonum
d28e7c29a2 Add ActiveRecord::Relation#readonly?
Indicates whether a relation was marked readonly.
2024-05-27 21:51:04 +02:00
Rafael Mendonça França
9232363f4a
Merge pull request #51929 from Skalar/source-reflection-regression
Make source_reflection return nil when no name
2024-05-27 15:22:19 -04:00
Theodor Tonum
2364b4243d Make source_reflection return nil when no name 2024-05-27 21:08:45 +02:00
Yasuo Honda
ae3c93df0c
Merge pull request #51859 from fatkodima/fix-partial_inserts-with-identity-cpk
Fix non-partial inserts for models with composite identity primary keys
2024-05-27 21:45:29 +09:00
zzak
db932716a6
Merge pull request #51923 from wonda-tea-coffee/fix-typo-in-puma-config
Fix typo
2024-05-27 19:53:18 +09:00
wonda-tea-coffee
e71ba8f914 Fix typo 2024-05-27 18:58:28 +09:00
Yasuo Honda
a658c68093
Merge pull request #51921 from zzak/railties-sqlite-non_existent-test
Re-enable railtie non_existent sqlite3 test from #51901
2024-05-27 18:03:18 +09:00
zzak
e2adebef43
Re-enable railtie non_existent sqlite3 test from #51901 2024-05-27 17:34:17 +09:00
David Heinemeier Hansson
1b3fc3c82e
Change asset pipeline default to Propshaft in Rails 8 (#51799)
* Change asset pipeline default to Propshaft

* Use :all for stylesheets when propshaft is active

* Switch to using propshaft as the default (still need to find a way to tests against sprockets too)

* Fix tests that rely on sprockets being used

* Fix Propshaft tests (#51913)

* Update railties/test/generators/shared_generator_tests.rb

Co-authored-by: Lázaro Nixon <lazaronixon@hotmail.com>

---------

Co-authored-by: Lázaro Nixon <lazaronixon@hotmail.com>
2024-05-25 20:48:35 -07:00
Petrik de Heus
d0a3e18d4d
Merge pull request #51867 from duffuniverse/add-missed-comma-to-instrumentation-guide
[ci skip] Add a comma in the Exceptions section of Active Support Instrumentation guide
2024-05-25 23:29:21 +02:00
Xavier Noria
4cde578c0e Restore original header for browser version guards 2024-05-25 19:27:30 +02:00
Ryuta Kamizono
f114a247aa
Merge pull request #51915 from nisusam/fix_symbol
Fix `+` symbol [ci skip]
2024-05-25 18:01:14 +09:00
nisusam
9622342950 Fix + symbol [ci skip] 2024-05-25 14:22:49 +05:30
Xavier Noria
0a9d844c9a Remove backticks from jemalloc
jemalloc is the name of a project.
2024-05-25 09:42:38 +02:00
Xavier Noria
91f9d640bd Edit pass over the 7.2 release notes 2024-05-25 09:33:58 +02:00
Rafael Mendonça França
bb3da8726b
Draft of the release notes 2024-05-24 20:42:13 +00:00
Rafael Mendonça França
3ccca0cc54
Merge pull request #51121 from jamiemccarthy/jm-fix-allow-browser-versions
Fix AllowBrowser versions
2024-05-24 16:27:14 -04:00
Rafael Mendonça França
fe4617fd7e
Merge pull request #51912 from Earlopain/aj-priority
Document what higher/lower priority numbers mean in ActiveJob guide [ci skip]
2024-05-24 16:26:52 -04:00
Rafael Mendonça França
548be67bce
Merge pull request #51911 from silva96/patch-2
Fix association_basics.md
2024-05-24 16:25:30 -04:00
Earlopain
2e8c0de787
Document what higher/lower priority numbers mean in ActiveJob guide
Or rather, what they could mean. What to do with priority numbers is up to the adapter implementation.

All adapters that support priority that I know of treat lower priority as more urgent:
* Backburner
* Delayed Job
* Que
* SolidQueue
* GoodJob (in v4)
2024-05-24 22:12:06 +02:00
Benjamín Silva
25b238568c
Fix association_basics.md
In this section the relation was renamed `:writer` so we need to reflect that in the examples.
2024-05-24 16:10:22 -04:00
Rafael Mendonça França
ad41f711ce
Merge pull request #51846 from simi/base64-standard-error
Catch StandardError during Base64 decoding in message encryptor.
2024-05-24 16:00:43 -04:00
Jamie McCarthy
dc34e293e0
ActionPack: fix BrowserBlocker versions
css-nesting is not fully supported until Chrome 120, Opera 106:
https://caniuse.com/css-nesting
https://developer.mozilla.org/en-US/docs/Web/CSS/Nesting_selector#browser_compatibility
2024-05-24 19:50:05 +00:00
Rafael Mendonça França
cff6b2cd8d
Merge pull request #51874 from stiig/fix-colspan-for-rails-routes
Fix colspan for representing search results in the rails routes
2024-05-24 15:47:05 -04:00