Hi, it’s Claudio Baccigalupo. Don’t be scared 🎃 this week’s changes to the Rails codebase are all treats. Let’s explore them.
New guide to multiple databases in Active Record
As part of the Rails Foundation effort, the refreshed guide is live, tackling the three-tier production configuration that new apps get by default.
Tuning performance for deployment guide open for review
A PR that updates the guide to performance tuning is open. Your feedback is helpful, especially if you have experience tuning Rails apps in production.
Don’t load Capybara and Selenium on boot in new applications
The generated Gemfile now declares capybara and selenium-webdriver with require: false. ActionDispatch::SystemTestCase already requires both when a system test is loaded, so test processes that don’t run system tests boot faster.
Don’t render authenticity tokens under the :header_only CSRF strategy
:header_only verifies requests by their Sec-Fetch-Site header and never reads a token, yet forms, button_to and csrf_meta_tags were still generating one on every render. Now they render none, so a page’s bytes no longer change from one request to the next.
Process each Action Cable connection’s commands in order
Commands from the same connection could previously run at the same time or out of order.
Scope immutable_strings_by_default to string columns
The setting applied to every column whose type subclassed ActiveModel::Type::String, so text columns and PostgreSQL’s xml, citext, ltree, tsvector and macaddr columns were inferred as :string, losing their type.
Render hidden=”until-found” as is
A string or symbol value of the hidden attribute is no longer replaced by "hidden":
tag.div(hidden: "until-found")
# Before: <div hidden="hidden"></div>
# After: <div hidden="until-found"></div>
Fix preloading has_many :through associations with source_type and conditions
There were four PRs this week fixing preloading of :through associations:
Post.preload(:tags, :inactive_tags).first.inactive_tags
# => no longer includes active tags
Fix left_joins and eager_load dropping an intermediate join
When the same through association was joined from different parent paths, the second path reused the join of the first, silently returning values from the wrong records.
Exclude default_order from exists? and calculations
exists? and calculations such as count already removed explicit ordering. Now they also remove default_order, which avoids invalid SQL on PostgreSQL.
Keep query block scoped optimizer hints on the subquery for MySQL
For count with limit, offset or distinct, all optimizer hints used to move to the outer query, while table-level hints like INDEX(posts idx) were silently ignored.
Deprecate ActiveRecord::Validations::NumericalityValidator
Active Record now uses ActiveModel::Validations::NumericalityValidator directly. The old constant still works with a deprecation warning.
Deprecate the option accessors on ColumnDefinition
Use options instead, for example column.options[:limit] instead of column.limit.
Fix CurrentAttributes defaults for attribute names given as strings
class Current < ActiveSupport::CurrentAttributes
attribute "currency", default: "USD"
end
Current.currency
# Before: nil
# After: "USD"
Match URL-decoded query parameter names when filtering logs
A parameter such as %70assword is now matched by a :password filter in request and redirect logs.
Add Northwest Territories to ActiveSupport::TimeZone::MAPPING
They no longer shares winter clocks with US Mountain time. Prefer Northwest Territories (or America/Inuvik) for users in that region.
Use Markdown as the default API docs markup
The README files of Railties, Active Support, Action View and Action Pack have all been converted from RDoc to Markdown.
Decode and encode PostgreSQL integer arrays in C
Reading or writing an integer[] or bigint[] column no longer allocates one String per element.
Other performance PRs that landed this week: cache the keyed HMAC in MessageVerifier, speed up Time.zone.today and Date, unroll the form builder helpers, call render_in optimistically, reduce allocations when building URLs, and make Symbol#to_param return the frozen Symbol#name.
You can view the whole list of changes here. We had 33 contributors to the Rails codebase this past week!
Until next time!
Subscribe to get these updates mailed to you.