aboutsummaryrefslogtreecommitdiffstats
path: root/guides
diff options
context:
space:
mode:
authorabhishek <bigbeliever@gmail.com>2014-09-16 23:53:02 +0530
committerabhishek <bigbeliever@gmail.com>2014-09-16 23:53:02 +0530
commit00e30b8f1cd364bdd07b1d87a716d571c75cc4da (patch)
treeb4c939583474a57ae9fa4d645b5a0a08332162eb /guides
parent1bdb233bc22cbd2e557d2e0ccca21f04b15eb65a (diff)
downloadrails-00e30b8f1cd364bdd07b1d87a716d571c75cc4da.tar.gz
rails-00e30b8f1cd364bdd07b1d87a716d571c75cc4da.tar.bz2
rails-00e30b8f1cd364bdd07b1d87a716d571c75cc4da.zip
[guides] 4.2 release notes: added technical details for Adequate Record
Diffstat (limited to 'guides')
-rw-r--r--guides/source/4_2_release_notes.md37
1 files changed, 33 insertions, 4 deletions
diff --git a/guides/source/4_2_release_notes.md b/guides/source/4_2_release_notes.md
index cb461feff8..5aed0c9358 100644
--- a/guides/source/4_2_release_notes.md
+++ b/guides/source/4_2_release_notes.md
@@ -52,11 +52,40 @@ deserialize it at run time.
### Adequate Record
-Rails 4.2 comes with a performance improvement feature called Adequate Record
-for Active Record. A lot of common queries are now up to twice as fast in Rails
-4.2!
+Adequate Record is a set of refactorings that make Active Record `find` and `find_by` methods and some association queries upto 2x faster.
-TODO: add some technical details
+It works by caching SQL query patterns while executing the Active Record calls. The cache helps skip parts of the computation involved in the transformation of the calls into SQL queries. More details in [Aaron Patterson's post](http://tenderlovemaking.com/2014/02/19/adequaterecord-pro-like-activerecord.html).
+
+Nothing special has to be done to activate this feature. Most `find` and `find_by` calls and association queries will use it automatically. Examples:
+
+```ruby
+Post.find 1 # caches query pattern
+Post.find 2 # uses the cached pattern
+
+Post.find_by_title 'first post' # caches query pattern
+Post.find_by_title 'second post' # uses the cached pattern
+
+post.comments # caches query pattern
+post.comments(true) # uses cached pattern
+```
+
+The caching is not used in the following scenarios:
+
+- The model has a default scope
+- The model uses single table inheritence to inherit from another model
+- `find` with a list of ids. eg:
+
+ ```ruby
+ Post.find(1,2,3)
+ OR
+ Post.find [1,2]
+ ```
+
+- `find_by` with sql fragments:
+
+ ```ruby
+ Post.find_by "published_at < ?", 2.weeks.ago
+ ```
### Web Console