Friday, January 12, 2024

Updated Puma configuration, Object#with block support, and more!

Posted by vipulnsward

Hi! Vipul here with the second edition of This Week in Rails for 2024!

This second week continues with a flurry of activity with more than 140+ changes making in.

Lets dive into some of these changes!

Update the default Puma configuration
There was an extensive discussion in this issue about - setting a new default for the Puma thread count, over the last few days. Give it a read to get some insights from different members in community sharing details about latency vs throughput tradeoffs wrt to the number of threads in Puma config. Based on this discussion, the default number of threads in Puma config has now been updated from 5 to 3.

Yield instance to Object#with block
The introduction of the block argument means that Object#with can now achieve something like below:

client.with(timeout: 5_000) do |c|

Add explain support for methods like last, pluck and count
The object returned by explain now responds to pluck, first, last, average, count, maximum, minimum, and sum. Those new methods run EXPLAIN on the corresponding queries, ex:


# EXPLAIN SELECT MAX(`users`.`id`) FROM `users`

Do not generate server pidfile in production environments
When running Rails applications with Docker containers may fail to restart if they crashed (e.g. because of OOM) because the /rails/tmp/pids/ file is already present. To avoid this, new Apps now avoid generating this pid file.

Support :on option in #set_callback
Introduces ActiveRecord::Transactions::ClassMethods#set_callback which behaves like ActiveSupport::Callbacks::ClassMethods#set_callback with support for the :on option available on #after_commit and #after_rollback callbacks. Ex:

class User
  set_callback :commit, :after, :do_some_work, on: :update

Add default: support for ActiveSupport::CurrentAttributes.attribute
This change extends the .attribute class method to accept a :default option for its list of attributes:

class Current < ActiveSupport::CurrentAttributes
  attribute :counter, default: 0

Add oven-sh/setup-bun to GitHub CI when generating an app with bun
This is a follow-up change for adding GitHub CI workflow by default to new applications. It adds oven-sh/setup-bun to GitHub CI when generating an app with bun, for proper CI env setup.

Prevent unnecessary application reloads in development
This PR fixes this issue by ensuring the application reloads correctly according to Rails.autoloaders.main.dirs, thereby preventing unnecessary reloads, ex: when editing app/ would trigger a reload.

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

Until next time!

Subscribe to get these updates mailed to you.