This Week in Rails

July 4, 2022

Improved PostgreSQL support, performance improvements and more...

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

Instead of specifying a long list of ids for batch queries (WHERE IN (...ids...)), Active Record will iterate in ranges (WHERE id >= num1 AND id < num2).

When creating indexes with CONCURRENTLY, you could to end up with an invalid index. You can now ask an index if it's valid.

Add support for PostgreSQL exclusion constraints
This extends Active Record's migration/schema dumping to support PostgreSQL exclusion constraints.

Add :force support to ActiveSupport::Cache::Store#fetch_multi
Setting force: true forces a cache “miss,” meaning we treat the cached values as missing even if present. #fetch_multi  now supports all of the #fetch options.

Previously, when saving a record, Active Record would perform an extra query to check for the uniqueness of each attribute having a uniqueness validation, even if that attribute hadn't changed.
If the database has the corresponding unique index, then this validation can never fail for persisted records, and we can safely skip it.

Make Notifications::Fanout faster and safe
This changes aims to improve ActiveSupport::Notifications::Fanout. It should make subscribing/unsubscribing to in-flight topics safer. It is also significantly faster for all cases, except for evented.

As the strings returned from strip_tags contain no HTML elements and the basic entities are escaped, they are safe to be included as-is as PCDATA in HTML content. Tagging them as html-safe avoids double-escaping entities when being concatenated to a SafeBuffer during rendering.

When creating a new Rails application you can use the --skip-* options to disable frameworks. After upgrading to a new version to Rails you can update all configurations by running bin/rails app:update. This change makes sure the disabled frameworks remain disabled after upgrading.

Cache stores can enable connection pooling using a single pool option. This option will default to true now for MemCacheStore and RedisCacheStore.

The MessageVerifier and MessageEncryptor constructors now accept a :urlsafe option. When enabled, this option ensures that messages use a URL-safe encoding.

All batching methods can be called with a descending order. This change adds that ability to in_batches when called without a block.

Previously, if the database exists but has not been populated with tables, db:prepare would run all migrations.
Now db:prepare will load the schema, then run any remaining migrations, to bring the database up to state.

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