Monday, July 4, 2022

Improved PostgreSQL support, performance improvements and more...

Posted by p8

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

Optimize Active Record batching

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).

Add validity for PostgreSQL indexes

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.

Avoid validating a unique field if it has not changed and is backed by a unique index

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.

Strings returned from strip_tags are correctly tagged html_safe?

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.

Correctly check if frameworks are disabled when running app:update

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.

Enable connection pooling by default for MemCacheStore and RedisCacheStore

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

Add :urlsafe option to MessageVerifier and MessageEncryptor constructors

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

Support calling in_batches with descending order without a block

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

Allow db:prepare to load the schema if the database already exists but is empty

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!