Friday, June 28, 2024

Immutable Rails Cache Header, Local Assigns in Strict Local Templates, Threaded Active Storage Mirror Service

Posted by zzak

Hi, it’s zzak. Let’s explore this week’s changes in the Rails codebase.

Support “immutable” directive in Cache-Control
This PR adds a new option to the expires_in method to support the immutable directive for the “Cache-Control” header.

Also pass “local_assigns” to strict locals templates
When using Strict Locals in a partial, local_assigns is now passed to the view in order to workaround an issue where trying to access the default values of a name that is also a reserved Ruby keyword.

Fix mailer templates to be RuboCop compliant
An issue was fixed with the mailer generator and scaffolding to make the generated code RuboCop compliant. This would impact newly generated apps, that create a mailer or a scaffold would immediately fail in the generated CI configuration by default.

Correctly generate Devcontainer setting for applications that using mysql2 gem
This PR ensures that applications using the mysql2 gem for their database adapter still work with the devcontainer command.

Don’t make rdoc generation take an unreasonable amount of time
Due to a bug in RDoc, which was only discovered recently, the docs-preview pipeline in Rails CI was taking far too long to finish. I hope you are taking advantage of this pipeline when submitting PRs to update Rails documentation.

Add a config for preserving timezone information when calling “to_time” on TimeWithZone object
When using Active Support’s to_time method on a TimeWithZone object, you can now configure whether to preserve the timezone or use the UTC offset.

Improve performance of Active Storage Mirror Service
This started as a FIXME in the original Active Storage implemenation for Mirror Service, but now methods being called across all services are done using threads. This should improve the performance for uploads, especially if there are multiple mirrors, however you should be aware that the underlying service must be thread-safe.

Add condensed #inspect for Pool, Adapter, Config
Previously, it was very easy to accidentally leak a database password in production logs if an error ends up calling inspect on a ConnectionPool or an individual connection (Adapter). This is due to the default #inspect output for Pools and Adapters being unnecessarily large, and both currently including passwords (through the DatabaseConfig of a Pool, and the internal configuration of an Adapter).

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 and deprecates the use of bin/rake stats directly.

You can view the whole list of changes here. We had 24 contributors to the Rails codebase this past week!

Until next time!

Subscribe to get these updates mailed to you.