diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-07-26 17:11:30 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-07-26 17:11:30 -0700 |
commit | 07a803c9f607b938f004b4adb6fe9abbad6fc8c4 (patch) | |
tree | 0cdb4d1d21a392181235870cadc755953fb11512 | |
parent | 4104de6a11c022e82a0fedd786cf39bc6c7bb62f (diff) | |
download | rails-07a803c9f607b938f004b4adb6fe9abbad6fc8c4.tar.gz rails-07a803c9f607b938f004b4adb6fe9abbad6fc8c4.tar.bz2 rails-07a803c9f607b938f004b4adb6fe9abbad6fc8c4.zip |
PERF: removing *args calls, do not call send on protected methods then they are public methods
-rw-r--r-- | lib/arel/algebra/relations/relation.rb | 38 | ||||
-rw-r--r-- | lib/arel/engines/sql/relations/compiler.rb | 27 |
2 files changed, 36 insertions, 29 deletions
diff --git a/lib/arel/algebra/relations/relation.rb b/lib/arel/algebra/relations/relation.rb index 3f6151e27b..b89abd5b8a 100644 --- a/lib/arel/algebra/relations/relation.rb +++ b/lib/arel/algebra/relations/relation.rb @@ -62,31 +62,29 @@ module Arel end end - protected - - def from_clauses - sources.blank? ? table_sql(Sql::TableReference.new(self)) : sources - end + def select_clauses + attributes.collect { |a| a.to_sql(Sql::SelectClause.new(self)) } + end - def select_clauses - attributes.collect { |a| a.to_sql(Sql::SelectClause.new(self)) } - end + def from_clauses + sources.blank? ? table_sql(Sql::TableReference.new(self)) : sources + end - def where_clauses - wheres.collect { |w| w.to_sql(Sql::WhereClause.new(self)) } - end + def where_clauses + wheres.collect { |w| w.to_sql(Sql::WhereClause.new(self)) } + end - def group_clauses - groupings.collect { |g| g.to_sql(Sql::GroupClause.new(self)) } - end + def group_clauses + groupings.collect { |g| g.to_sql(Sql::GroupClause.new(self)) } + end - def having_clauses - havings.collect { |g| g.to_sql(Sql::HavingClause.new(self)) } - end + def having_clauses + havings.collect { |g| g.to_sql(Sql::HavingClause.new(self)) } + end - def order_clauses - orders.collect { |o| o.to_sql(Sql::OrderClause.new(self)) } - end + def order_clauses + orders.collect { |o| o.to_sql(Sql::OrderClause.new(self)) } + end module Enumerable include ::Enumerable diff --git a/lib/arel/engines/sql/relations/compiler.rb b/lib/arel/engines/sql/relations/compiler.rb index dfc2489e77..abd0d0abfd 100644 --- a/lib/arel/engines/sql/relations/compiler.rb +++ b/lib/arel/engines/sql/relations/compiler.rb @@ -13,21 +13,30 @@ module Arel subquery = build_query("SELECT 1 FROM #{from_clauses}", build_clauses) query = "SELECT COUNT(*) AS count_id FROM (#{subquery}) AS subquery" else - query = build_query \ - "SELECT #{select_clauses.join(', ')}", - "FROM #{from_clauses}", + query = [ + "SELECT #{relation.select_clauses.join(', ')}", + "FROM #{relation.from_clauses}", build_clauses + ].compact.join ' ' end query end def build_clauses - clauses = build_query "", - (joins(self) unless joins(self).blank? ), - ("WHERE #{where_clauses.join(' AND ')}" unless wheres.blank? ), - ("GROUP BY #{group_clauses.join(', ')}" unless groupings.blank? ), - ("HAVING #{having_clauses.join(' AND ')}" unless havings.blank? ), - ("ORDER BY #{order_clauses.join(', ')}" unless orders.blank? ) + joins = joins(self) + wheres = relation.where_clauses + groups = relation.group_clauses + havings = relation.having_clauses + orders = relation.order_clauses + + clauses = [ "", + joins, + ("WHERE #{wheres.join(' AND ')}" unless wheres.empty?), + ("GROUP BY #{groups.join(', ')}" unless groups.empty?), + ("HAVING #{havings.join(' AND ')}" unless havings.empty?), + ("ORDER BY #{orders.join(', ')}" unless orders.empty?) + ].compact.join ' ' + engine.add_limit_offset!(clauses,{ :limit => taken, :offset => skipped }) if taken || skipped clauses << " #{locked}" unless locked.blank? clauses unless clauses.blank? |