aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/result.rb
diff options
context:
space:
mode:
authorBenjamin Quorning <benjamin@quorning.net>2016-06-24 09:49:42 +0200
committerBenjamin Quorning <benjamin@quorning.net>2016-06-24 11:43:48 +0200
commit763de2ac1c85d3e9f82639783a55244d6c0517c2 (patch)
treeb3ea6e9eec0572399f4d9d4d0c36867f86290ed9 /activerecord/lib/active_record/result.rb
parentaf834fb2c03358fe9a1b8fd9ec36eb5658a63260 (diff)
downloadrails-763de2ac1c85d3e9f82639783a55244d6c0517c2.tar.gz
rails-763de2ac1c85d3e9f82639783a55244d6c0517c2.tar.bz2
rails-763de2ac1c85d3e9f82639783a55244d6c0517c2.zip
Optimize ActiveRecord::Result#last
If you only want the last element of a result set, there's no need to create all of hash_rows. Also, add a test.
Diffstat (limited to 'activerecord/lib/active_record/result.rb')
-rw-r--r--activerecord/lib/active_record/result.rb3
1 files changed, 2 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/result.rb b/activerecord/lib/active_record/result.rb
index f45f664efe..b9fd0f5326 100644
--- a/activerecord/lib/active_record/result.rb
+++ b/activerecord/lib/active_record/result.rb
@@ -81,7 +81,8 @@ module ActiveRecord
end
def last
- hash_rows.last
+ return nil if @rows.empty?
+ Hash[@columns.zip(@rows.last)]
end
def cast_values(type_overrides = {}) # :nodoc: