Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

PERF: removing *args calls, do not call send on protected methods the…

…n they are public methods
  • Loading branch information...
commit 07a803c9f607b938f004b4adb6fe9abbad6fc8c4 1 parent 4104de6
@tenderlove tenderlove authored
View
38 lib/arel/algebra/relations/relation.rb
@@ -62,31 +62,29 @@ def primary_key
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
View
27 lib/arel/engines/sql/relations/compiler.rb
@@ -13,21 +13,30 @@ def select_sql
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?

0 comments on commit 07a803c

Please sign in to comment.
Something went wrong with that request. Please try again.