diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-07-26 16:35:15 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-07-26 16:35:15 -0700 |
commit | 4104de6a11c022e82a0fedd786cf39bc6c7bb62f (patch) | |
tree | ff37d737f107f83c31463420b423035fb96ab7d7 /lib/arel | |
parent | 21cf9e4a7214a97fa2c81c84cd970aac30311dda (diff) | |
download | rails-4104de6a11c022e82a0fedd786cf39bc6c7bb62f.tar.gz rails-4104de6a11c022e82a0fedd786cf39bc6c7bb62f.tar.bz2 rails-4104de6a11c022e82a0fedd786cf39bc6c7bb62f.zip |
PERF: cache christener, initialize hash in initialize
Diffstat (limited to 'lib/arel')
-rw-r--r-- | lib/arel/algebra/relations/operations/join.rb | 1 | ||||
-rw-r--r-- | lib/arel/engines/sql/christener.rb | 13 | ||||
-rw-r--r-- | lib/arel/engines/sql/formatters.rb | 5 |
3 files changed, 13 insertions, 6 deletions
diff --git a/lib/arel/algebra/relations/operations/join.rb b/lib/arel/algebra/relations/operations/join.rb index 83ebfc129f..72b4c9b8fe 100644 --- a/lib/arel/algebra/relations/operations/join.rb +++ b/lib/arel/algebra/relations/operations/join.rb @@ -8,6 +8,7 @@ module Arel @relation1 = relation1 @relation2 = relation2 @predicates = predicates + @attributes = nil end def name diff --git a/lib/arel/engines/sql/christener.rb b/lib/arel/engines/sql/christener.rb index a2a2da799a..2c96020554 100644 --- a/lib/arel/engines/sql/christener.rb +++ b/lib/arel/engines/sql/christener.rb @@ -1,13 +1,18 @@ module Arel module Sql class Christener - def name_for(relation) - @used_names ||= Hash.new(0) - (@relation_names ||= Hash.new do |hash, relation| + def initialize + # FIXME: this exists because all objects hash the same. :'( + @used_names = Hash.new(0) + @relation_names = Hash.new do |hash, relation| name = relation.table_alias ? relation.table_alias : relation.name @used_names[name] += 1 hash[relation] = name + (@used_names[name] > 1 ? "_#{@used_names[name]}" : '') - end)[relation.table] + end + end + + def name_for(relation) + @relation_names[relation.table] end end end diff --git a/lib/arel/engines/sql/formatters.rb b/lib/arel/engines/sql/formatters.rb index cdbda5ea33..de8278479d 100644 --- a/lib/arel/engines/sql/formatters.rb +++ b/lib/arel/engines/sql/formatters.rb @@ -1,13 +1,14 @@ module Arel module Sql class Formatter - attr_reader :environment - delegate :christener, :engine, :to => :environment + attr_reader :environment, :christener + delegate :engine, :to => :environment delegate :name_for, :to => :christener delegate :quote_table_name, :quote_column_name, :quote, :to => :engine def initialize(environment) @environment = environment + @christener = environment.christener end end |