aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcel Molina <marcel@vernix.org>2005-10-09 21:42:40 +0000
committerMarcel Molina <marcel@vernix.org>2005-10-09 21:42:40 +0000
commit89733eaecffef3c1ad55345677411c872b1c99e4 (patch)
tree05c79ea599afc091b2c57e3e5c56fb68ce392882
parent68a322005d367981ba72c6a667c16dd171803869 (diff)
downloadrails-89733eaecffef3c1ad55345677411c872b1c99e4.tar.gz
rails-89733eaecffef3c1ad55345677411c872b1c99e4.tar.bz2
rails-89733eaecffef3c1ad55345677411c872b1c99e4.zip
Optimization refactoring for add_limit_offset!. In partial fullfilment of #1236.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2509 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r--activerecord/CHANGELOG2
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb12
-rwxr-xr-xactiverecord/lib/active_record/connection_adapters/mysql_adapter.rb8
3 files changed, 13 insertions, 9 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index 809c567127..a181c89dde 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Optimization refactoring for add_limit_offset!. In partial fullfilment of #1236. [skaes@web.de]
+
* Add ability to get all siblings, including the current child, with acts_as_tree. Recloses #2140. [Michael Schuerig <michael@schuerig.de>]
* Add geometric type for postgresql adapter. #2233 [akaspick@gmail.com]
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
index a3d22ed809..90dc951b6d 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
@@ -73,8 +73,7 @@ module ActiveRecord
# Alias for #add_limit_offset!.
def add_limit!(sql, options)
- return unless options
- add_limit_offset!(sql, options)
+ add_limit_offset!(sql, options) if options
end
# Appends +LIMIT+ and +OFFSET+ options to a SQL statement.
@@ -84,9 +83,12 @@ module ActiveRecord
# generates
# SELECT * FROM suppliers LIMIT 10 OFFSET 50
def add_limit_offset!(sql, options)
- return if options[:limit].nil?
- sql << " LIMIT #{options[:limit]}"
- sql << " OFFSET #{options[:offset]}" if options.has_key?(:offset) and !options[:offset].nil?
+ if limit = options[:limit]
+ sql << " LIMIT #{limit}"
+ if offset = options[:offset]
+ sql << " OFFSET #{offset}"
+ end
+ end
end
end
end
diff --git a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
index d56e1f90da..886363bcbe 100755
--- a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
@@ -195,11 +195,11 @@ module ActiveRecord
def add_limit_offset!(sql, options) #:nodoc
- if options[:limit]
- if options[:offset].blank?
- sql << " LIMIT #{options[:limit]}"
+ if limit = options[:limit]
+ unless offset = options[:offset]
+ sql << " LIMIT #{limit}"
else
- sql << " LIMIT #{options[:offset]}, #{options[:limit]}"
+ sql << " LIMIT #{offset}, #{limit}"
end
end
end