Commit Graph

92092 Commits

Author SHA1 Message Date
Jean Boussier
c79671cc5c
Merge pull request #52254 from ddux/patch-1
[ci skip] Update config/boot.rb contents in initialization.md
2024-07-05 10:00:54 +02:00
Jean Boussier
2edad3c542
Merge pull request #52272 from fatkodima/skip-triggering-instantiation-notification
Skip triggering "instantiation.active_record" notification when there are no records
2024-07-05 09:59:55 +02:00
fatkodima
2410312733 Skip triggering "instantiation.active_record" notification when there are no records 2024-07-04 21:43:46 +03:00
eileencodes
4fa56814f1
fix newlines
New lines for these were off, only the new options were put on a new
line so the code looked awkward. I'd rather just oneline it.
2024-07-03 08:41:48 -04:00
Eileen M. Uchitelle
71e14aa7e9
Merge pull request #51735 from heka1024/encryption-compressor
Introduce `compressor` option to `ActiveRecord::Encryption::Encryptor`
2024-07-03 08:39:13 -04:00
heka1024
75421601ce Introduce compressor option to ActiveRecord::Encryption::Encryptor 2024-07-03 18:48:07 +09:00
Xavier Noria
738fde4782
Merge pull request #52251 from rails/fxn/edits
Edits in the dev containers guide
2024-07-02 11:00:04 +02:00
Xavier Noria
47a5d067d6 Edits in the dev containers guide 2024-07-02 10:57:00 +02:00
Dakota Dux
e556176457
Update initialization.md
The code block that contains the code in`config/boot.rb` is missing the line that requires bootsnap/setup.
2024-07-01 22:46:17 -05:00
Aaron Patterson
35a4946d1c
Merge pull request #52094 from ioquatix/rack-3-streaming
Utilize Rack 3 streaming.
2024-07-01 17:39:11 -07:00
Petrik de Heus
599023dc03
Merge pull request #52217 from neanias/neanias/rework-link-text-for-accessibility-in-migrations-guide
Replace "here" link titles with meaningful titles [ci skip]
2024-07-01 21:47:33 +02:00
Will Mathewson
3ae8d7b863
Replace "here" link titles with meaningful titles
For accessibility reasons[1], it's recommended not to use "here"/"click
here"/"more" as the title for a link. When screen reader users are
tabbing through all links on the page, they'll miss the context of "read
more about X" preceding the "here". Thankfully, the sentences in the are
largely good to go, so the "here" can be dropped in favour of the last
part of the sentence to give the link title more meaning.

Some of these text changes may seem trivial, but when considering the
link text outwith its context sentences, the text has some more meaning
for those reading them through screen readers. (e.g. "API documentation"
-> "`number_to_currency` API documentation")

[1]: https://www.gov.uk/guidance/content-design/links#writing-link-text
2024-07-01 20:05:04 +01:00
Petrik de Heus
ee97ab24fc
Merge pull request #52246 from heka1024/immutable-http-cache-doc [ci-skip]
Document `immutable` option in `expires_in`
2024-07-01 21:01:00 +02:00
heka1024
a1a0931e13 Document immutable option in expires_in 2024-07-02 03:33:21 +09:00
Jean Boussier
d43ee20881
Merge pull request #52234 from kwstannard/indifferent
refactor HashWithIndifferentAccess#to_hash
2024-06-30 09:55:26 +02:00
Kelly Wolf Stannard
ed5d646127 Optimize HashWithIndifferentAccess#to_hash
Creating a copy by starting from an empty hash and inserting
keys one by one is inneficient because unless the hash is
very small, Ruby will have to reallocate the hash multiple
times until it reaches the same saize as the original.

And every time it happens, keys will have to be re-hashes.

While we're at it, instead of using the generic `convert_value`
we define a dedicated method which saves on needless checks.

Co-Authored-By: Jean Boussier <jean.boussier@gmail.com>

```ruby

require "bundler/inline"

gemfile(true) do
  source "https://rubygems.org"

  gem "activesupport", path: '.'
  gem 'benchmark-ips'
  gem 'benchmark-memory'
end

require "active_support"
require "active_support/core_ext/hash/indifferent_access"
require 'benchmark/ips'

module ActiveSupport
  class KwstannardHWIA < HashWithIndifferentAccess
    def to_hash
      Hash[self]
        .transform_values! { |v| convert_value(v, conversion: :to_hash) }
        .tap { |h| set_defaults(h) }
    end
  end

  class ByrootHWIA < HashWithIndifferentAccess
    def to_hash
      copy = Hash[self]
      copy.transform_values! { |v| convert_value_to_hash(v) }
      set_defaults(copy)
      copy
    end

    private

    def convert_value_to_hash(value)
      if value.is_a? Hash
        value.to_hash
      elsif value.is_a?(Array)
        value.map { |e| convert_value_to_hash(e) }
      else
        value
      end
    end
  end
end

flat = Hash[(1..9).to_a.product([1])]
flat_baseline = ActiveSupport::HashWithIndifferentAccess.new(flat)
flat_k = ActiveSupport::KwstannardHWIA.new(flat)
flat_b = ActiveSupport::ByrootHWIA.new(flat)

Benchmark.ips do |x|
  x.report("original") { flat_baseline.to_hash }
  x.report("kwstannard") { flat_k.to_hash }
  x.report("byroot") { flat_b.to_hash }
  x.compare!(order: :baseline)
end

long_flat = Hash[(1..100).to_a.product([1])]
long_flat_baseline = ActiveSupport::HashWithIndifferentAccess.new(long_flat)
long_flat_k = ActiveSupport::KwstannardHWIA.new(long_flat)
long_flat_b = ActiveSupport::ByrootHWIA.new(long_flat)

Benchmark.ips do |x|
  x.report("original") { long_flat_baseline.to_hash }
  x.report("kwstannard") { long_flat_k.to_hash }
  x.report("byroot") { long_flat_b.to_hash }
  x.compare!(order: :baseline)
end

deep_baseline = ActiveSupport::HashWithIndifferentAccess.new(flat.dup)
3.times.reduce(deep_baseline) { |deep, _| deep[:deep] = ActiveSupport::HashWithIndifferentAccess.new(flat.dup) }

deep_k = ActiveSupport::KwstannardHWIA.new(flat.dup)
3.times.reduce(deep_k) { |deep, _| deep[:deep] = ActiveSupport::KwstannardHWIA.new(flat.dup) }

deep_b = ActiveSupport::ByrootHWIA.new(flat.dup)
3.times.reduce(deep_b) { |deep, _| deep[:deep] = ActiveSupport::ByrootHWIA.new(flat.dup) }

Benchmark.ips do |x|
  x.report("original") { deep_baseline.to_hash }
  x.report("kwstannard") { deep_k.to_hash }
  x.report("byroot") { deep_b.to_hash }
  x.compare!(order: :baseline)
end

```

```
$ ruby /tmp/to_hash.rb
Fetching gem metadata from https://rubygems.org/..........
Resolving dependencies...
ruby 3.3.1 (2024-04-23 revision c56cd86388) [arm64-darwin23]
Warming up --------------------------------------
            original    92.830k i/100ms
          kwstannard   125.443k i/100ms
              byroot   139.810k i/100ms
Calculating -------------------------------------
            original    968.200k (± 2.9%) i/s -      4.920M in   5.086600s
          kwstannard      1.268M (± 2.9%) i/s -      6.398M in   5.049545s
              byroot      1.397M (± 2.9%) i/s -      6.990M in   5.008404s

Comparison:
            original:   968200.3 i/s
              byroot:  1397069.4 i/s - 1.44x  faster
          kwstannard:  1268207.5 i/s - 1.31x  faster

ruby 3.3.1 (2024-04-23 revision c56cd86388) [arm64-darwin23]
Warming up --------------------------------------
            original    11.051k i/100ms
          kwstannard    15.865k i/100ms
              byroot    17.778k i/100ms
Calculating -------------------------------------
            original    109.059k (± 5.1%) i/s -    552.550k in   5.082820s
          kwstannard    157.499k (± 7.4%) i/s -    793.250k in   5.072103s
              byroot    177.066k (± 7.2%) i/s -    888.900k in   5.052601s

Comparison:
            original:   109059.1 i/s
              byroot:   177065.9 i/s - 1.62x  faster
          kwstannard:   157499.0 i/s - 1.44x  faster

ruby 3.3.1 (2024-04-23 revision c56cd86388) [arm64-darwin23]
Warming up --------------------------------------
            original    22.249k i/100ms
          kwstannard    30.132k i/100ms
              byroot    34.116k i/100ms
Calculating -------------------------------------
            original    224.127k (± 1.7%) i/s -      1.135M in   5.064253s
          kwstannard    295.912k (± 5.9%) i/s -      1.476M in   5.007324s
              byroot    343.225k (± 1.7%) i/s -      1.740M in   5.070715s

Comparison:
            original:   224127.0 i/s
              byroot:   343224.6 i/s - 1.53x  faster
          kwstannard:   295912.4 i/s - 1.32x  faster
```
2024-06-30 09:33:55 +02:00
Ryuta Kamizono
88924dd9d4
Merge pull request #52236 from takmar/fix-broken-link-in-dev-containers-guide
Fix broken links in Dev Containers start guide [ci skip]
2024-06-29 23:26:31 +09:00
takmar
ee2c283eb3 Fix broken links in Dev Containers start guide 2024-06-29 20:31:18 +09:00
Jean Boussier
d2b739c3c8
Merge pull request #52235 from fatkodima/fix-deadlock-in-checkout
Fix a deadlock in `ConnectionPool#checkout`
2024-06-29 10:52:09 +02:00
Petrik de Heus
21280a1616
Merge pull request #52231 from JuanVqz/railties/rails-stats-changelog
Add `bin/rake stats` deprecation changelog [ci skip]
2024-06-29 08:52:05 +02:00
fatkodima
803c78d9f4 Fix a deadlock in ConnectionPool#checkout 2024-06-29 02:35:16 +03:00
Xavier Noria
b9d6759401 Style pass over active_record/associations/builder/association.rb
I was reading this source code and made a few edits on passing to ensure
style details agree within the file itself and Rails.

The addition of "# noop" makes the method body look similar to other
analogous ones in the same file (not shown in the diff).
2024-06-28 18:35:13 +02:00
Juan Vásquez
3d737cd8ef
Update CHANGELOG.md
Co-authored-by: Petrik de Heus <petrik@deheus.net>
2024-06-28 10:14:10 -06:00
bhumi1102
f0f624bde4
[RF-DOCS] Action View Form Helpers Guide [ci-skip] (#51936)
In addition to updating the code examples and editing text for clarity and flow, here some more details on some of the changes:

- [X] Do we still need an HTML5 warning at the end of the 1st section? It's pretty standard these days.
--> agree, removed.
- [X] Not sure the output of `_form_with model: @article`_ is 100% correct, might need to double check that.
--> yes. updated this example and got the HTML output from my "guides playground" rails app.
- [X] When we mention `record.persisted?` in record identification, could be a good plug to link to the Active Model guide on that.
--> Hm...there is no direction mention, other than this https://guides.rubyonrails.org/active_model_basics.html#conversion
- [X] Similar to STI, link to the guide / reference on it.
- [X] Time Zone and Country Select should likely be broken into separate sub-sections (I don't mind still mentioning country select)
- [X]  Would the file upload example would be better with a CSV for local processing, rather than showing saving to local disk? (which is probably a very uncommon usage?)
- [X] The _labeled_form_with_ example could likely be simplified with `_**options_` being all that it takes, instead of explicitly showing all possible kwargs.
- [X]  It may be better to show "complex forms" (section 10) right after the parameters (section 8), moving "forms to external resources" down... just because complex forms require exactly the fields_for incantation that was detailed further under the parameters section, so it seems a better continuation. (or potentially even reversed? complex forms then params? not sure)
- [X] Under "complex forms", adding fields on the flow could be slightly expanded, it feels very "go figure". 
--> Yeah, not sure what to do about this one. Was thinking about removing it as there is not built-in support to showcase.

---------

Co-authored-by: Ridhwana <Ridhwana.Khan16@gmail.com>
Co-authored-by: Petrik de Heus <petrik@deheus.net>
Co-authored-by: Amanda Perino <58528404+AmandaPerino@users.noreply.github.com>
Co-authored-by: Karl Lingiah <karl@superchilled.co.uk>
2024-06-28 17:49:36 +02:00
Juan Vasquez
2f580264d5 Add bin/rake stats deprecation changelog
Related #47713
2024-06-28 07:55:44 -06:00
Rafael Mendonça França
6045f257fb
Merge pull request #52132 from skipkayhil/hm-rm-logger-predicates
Remove obsolete Logger severity predicates
2024-06-26 19:03:11 -04:00
Hartley McGuire
564e427c05
Remove obsolete Logger severity predicates
The Logger severity predicates have existed since the [introduction of
Logger][1]. However, these methods only looked at the `level` instance
variable, so they did not work with the [thread safe implementation][2]
of temporary log levels in Rails.

Since then, the Logger severity predicates were [updated][3] to use the
`level` method instead of the instance variable, making Rails' severity
predicate overrides obsolete.

This commit removes Rails' custom severity predicates in favor of
Logger's implementation, since the new implementation was released in
Logger 1.4.2 and came bundled with Ruby 2.7.0.

[1]: ruby/logger@525b58d97e
[2]: rails/rails@629efb6057
[3]: ruby/logger@7365c995bf
2024-06-26 21:19:12 +00:00
Rafael Mendonça França
292c127d46
Merge pull request #47713 from JuanVqz/railties/thor-stats-task
Use Thor for built-in stats task
2024-06-26 17:06:35 -04:00
Rafael Mendonça França
fca2a5e8a6
Merge pull request #51733 from seanpdoyle/document-yield-head
Mention `yield :head` in Guides
2024-06-26 17:03:40 -04:00
Rafael Mendonça França
004ab15650
Merge pull request #52215 from p8/railties/document-action-mailer-perform-caching
Document `action_mailer.perform_caching` in environment files. [ci-skip]
2024-06-26 17:01:38 -04:00
Rafael Mendonça França
a1259c7834
Merge pull request #52220 from jcbages/patch-1
[ci skip] Update getting_started.md
2024-06-26 16:59:35 -04:00
Rafael Mendonça França
8a452230c5
Merge pull request #52224 from Earlopain/rake-rdoc-abort
Fix `rake rdoc` when the timestamp file is empty
2024-06-26 16:57:55 -04:00
Rafael Mendonça França
999df686de
Merge pull request #52197 from heka1024/cache-controler-immutable
Support `immutable` directive in Cache-Control
2024-06-26 16:23:19 -04:00
Rafael Mendonça França
5103ba86e4
Merge pull request #52222 from Earlopain/skip-sprockets-newline
Fix an extra newline in `development.rb` when sprocket gets skipped
2024-06-26 16:18:22 -04:00
Rafael Mendonça França
862f402651
Merge pull request #52209 from bensheldon/strict-local-assigns-defaults
Document undefined `local_assigns` when using Strict Locals with defaults
2024-06-26 16:17:33 -04:00
Rafael Mendonça França
716e4a7d32
Merge pull request #52091 from jasonkim/to-time-use-timezone
Add a config for preserving timezone information when calling `to_time` on TimeWithZone object
2024-06-26 16:16:05 -04:00
Rafael Mendonça França
f46d06b3b5
Merge pull request #52031 from matthewd/quieter-to_time
Don't emit to_time deprecations in known-safe contexts
2024-06-26 16:09:59 -04:00
Rafael Mendonça França
acc8f3dfdf
Merge pull request #52214 from louim/bugfix/guide-menu-overflow
Fix guide menu overflow [ci skip]
2024-06-26 16:03:06 -04:00
Rafael Mendonça França
9d671f17c7
Merge pull request #52225 from Earlopain/rdoc-hanging
Don't make rdoc generation take an unreasonable amount of time
2024-06-26 15:59:42 -04:00
Rafael Mendonça França
9f31032b74
Merge pull request #52199 from rubys/rubocop-mailer-generator
Fix mailer templates to be rubocop compliant
2024-06-26 15:54:39 -04:00
Earlopain
979e308312
Don't make rdoc generation take an unreasonable amount of time
On CI, this takes about 8 hours. On my PC I canceled after 3.

I suspect this comment in rdoc to be relevant (since this method is where it is stuck): 4b84660690/lib/rdoc/mixin.rb (L68-L71)
Removing a few includes eventually makes it complete. It doesn't seem to matter which ones you remove.

https://github.com/rails/rails/pull/52185 was the trigger for this.
2024-06-26 17:53:43 +02:00
Earlopain
540103c6eb
Fix rake rdoc when the timestamp file is empty
This happens when rdoc fails during generation as the timestamp
is only written on successful attemps. The file is created anyways though
2024-06-26 17:07:25 +02:00
Eugene Kenny
659150f000
Merge pull request #52221 from heka1024/remove-unused-constant
Remove unused constant in `MySQLDatabaseTasks`
2024-06-26 13:42:06 +01:00
Earlopain
d8534d40e4
Fix an extra newline in development.rb when sprocket gets skipped 2024-06-26 12:43:17 +02:00
heka1024
45c4802459 Remove unused constant in MySQLDatabaseTasks 2024-06-26 16:43:00 +09:00
Juan Camilo Bages
bcca960d12
Update getting_started.md
- change single quotes to double quotes
- pass article as a local variable instead of instance varialbe in `comments/_form.html.erb`
2024-06-26 02:58:17 -04:00
Louis-Michel Couture
1e4be48f95
Fix guide menu overflow [ci skip]
This is a follow-up to 92b65a0f7e8c07942547d93df4a60a64088ff53f.
It's also a temporary fix until we can find a better solution.
2024-06-25 09:47:26 -04:00
Petrik
a787333b04 Document action_mailer.perform_caching in environment files.
This setting is set to false in all enviroments, but it's a bit unclear
why this needs to be set.
2024-06-25 15:46:10 +02:00
Ben Sheldon [he/him]
fe03a19175
Document undefined local_assigns when using Strict Locals with defaults 2024-06-24 08:25:15 -07:00
Juan Vasquez
df64ba0a06 Use Thor for built-in stats task
Currently, we use both Thor and Rake for `bin/rails` commands.
We eventually want to get all the built-ins task promoted to Thor Commands.
This migrates the `stats` task to Thor.
2024-06-24 09:12:21 -06:00