This Week in Rails

February 9, 2024

Rails Foundation Docs, Query Logs source_location, Dockerfile gets jemalloc

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

Rails Foundation Docs
A team has been formed to improve the existing Rails documentation. PRs from this project will stay open for one week for community review.
Open this week:
  • ActiveJob.perform_all_later
  • Action Text
  • Action Mailbox
More to come!

Properly synchronize "Mysql2Adapter#active?" and "TrilogyAdapter#active?"
As well as disconnect! and verify!.
This generally isn’t a big problem as connections must not be shared between threads, but is required when running transactional tests or system tests and could lead to a SEGV.

Implement “Rails::TestUnitReporter#prerecord”
By adding this method to Rails TestUnitReporter class, Minitest will pick it up and invoke it before invoking the test, allowing to print the test name in advance.
This is useful to debug slow and stuck tests by turning on verbose mode. This way the stuck test name is printed before the process deadlocks.

Fix JSON-encoding ActiveStorage::Filename
This PR fixes a bug where quotes were missing from the filename, generating invalid json.
JSON.generate(foo: ActiveStorage::Filename.new("bar.pdf")) # => '{"foo":bar.pdf}'

Support ":source_location" tag option for query log tags
This PR adds support for showing where a query is defined the Rails logs when using Active Record Query Logs.
# application.rb
config.active_record.query_log_tags_enabled = true
config.active_record.query_log_tags = [ :source_location ]

Setup jemalloc in default Dockerfile to optimize memory allocation
Ruby’s use of malloc can create memory fragmentation problems, especially when using multiple threads like Puma does.
Switching to an allocator that uses different patterns to avoid fragmentation can decrease memory usage by a substantial margin.

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

Until next time!

About This Week in Rails

Your weekly inside scoop of interesting commits, pull requests and more from Rails.