This Week in Rails

May 14, 2022

More async queries, pattern matching and no more autoclosed PRs!

Hi, this is Petrik, bringing you the latest news from the Rails world.

Async aggregate and find_by queries
Active Record async support was limited to loading collections, but among the not so fast queries that would benefit from asynchronicity you often find aggregates as well as hand crafted find_by_sql queries.
We now support the following methods:
  • async_count
  • async_sum
  • async_minimum
  • async_maximum
  • async_average
  • async_pluck
  • async_pick
  • async_find_by_sql
  • async_count_by_sql

When sessions are not stored in cookies, millions of sessions may be created and constantly evicted just for the CSRF token. This new configuration parameter will make it possible to store the CSRF token somewhere other than the session (i.e. in an encrypted cookie).

Being able to request html or screenshot from test code is nicer as it means you can do this selectively per-screenshot, rather than screenshotting/HTML dumping everything when running a test.

Reading these columns failed because their contents were not encrypted. Now, it will encrypt those values at record-creation time.

Stop autoclosing of PRs
While the idea of cleaning up the PRs list by nudging reviewers with the stale message and closing PRs that didn't got a review in time could work for the maintainers, in practice it discourages contributors to submit contributions.

This provides the Ruby 2.7+ pattern matching interface for hash patterns, which allows the user to pattern match against anything that includes the ActiveModel::AttributeMethods module (e.g., ActiveRecord::Base).

Previously calculations would make a query even when passed a contradiction, such as User.where(id: []).count. We no longer perform a query in that scenario.

The option --name will override the application name to be different from the folder name.
This allows applications to specify the maximum number of records that will be destroyed in a single background job by the dependent: :destroy_async association option. If the number of dependent records is greater than this configuration, the records will be destroyed in multiple background jobs.

Since last time, 102 people contributed to Rails. As usual, there are too many changes to cover them all, but you can check out all of these here. Until next time!