Skip to content

Commit 31052d0

Browse files
authored
Merge pull request rails#49117 from akhilgkrishnan/general-async-release-note
[skip ci] Description added for `Active Record API for general async queries` in 7.1 release note
2 parents fea9ad3 + 04e0b4b commit 31052d0

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

guides/source/7_1_release_notes.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,38 @@ Please, see more details in the [autoloading guide](autoloading_and_reloading_co
172172

173173
### Active Record API for general async queries
174174

175-
TODO: Add description https://github.com/rails/rails/pull/44446
175+
A significant enhancement has been introduced to the Active Record API, expanding its
176+
[support for asynchronous queries](https://github.com/rails/rails/pull/44446). This enhancement
177+
addresses the need for more efficient handling of not-so-fast queries, particularly focusing on
178+
aggregates (such as `count`, `sum`, etc.) and all methods returning a single record or anything
179+
other than a `Relation`.
180+
181+
The new API includes the following asynchronous methods:
182+
183+
- `async_count`
184+
- `async_sum`
185+
- `async_minimum`
186+
- `async_maximum`
187+
- `async_average`
188+
- `async_pluck`
189+
- `async_pick`
190+
- `async_find_by_sql`
191+
- `async_count_by_sql`
192+
193+
Here's a brief example of how to use one of these methods, `async_count`, to count the number of published
194+
posts in an asynchronous manner:
195+
196+
```ruby
197+
# Synchronous count
198+
published_count = Post.where(published: true).count # => 10
199+
200+
# Asynchronous count
201+
promise = Post.where(published: true).async_count # => #<ActiveRecord::Promise status=pending>
202+
promise.value # => 10
203+
```
204+
205+
These methods allow for the execution of these operations in an asynchronous manner, which can significantly
206+
improve performance for certain types of database queries.
176207

177208
### Allow templates to set strict `locals`.
178209

0 commit comments

Comments
 (0)