From 73a431a50b42e56697fed801d27470cd7d8f7990 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Mon, 10 Feb 2014 19:33:48 -0200 Subject: Avoid using deprecated arel constants --- activerecord/lib/active_record/associations/join_dependency.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'activerecord/lib/active_record/associations/join_dependency.rb') diff --git a/activerecord/lib/active_record/associations/join_dependency.rb b/activerecord/lib/active_record/associations/join_dependency.rb index 295dccf34e..27069157be 100644 --- a/activerecord/lib/active_record/associations/join_dependency.rb +++ b/activerecord/lib/active_record/associations/join_dependency.rb @@ -163,7 +163,7 @@ module ActiveRecord def make_outer_joins(parent, child) tables = table_aliases_for(parent, child) - join_type = Arel::OuterJoin + join_type = Arel::Nodes::OuterJoin joins = make_constraints parent, child, tables, join_type joins.concat child.children.flat_map { |c| make_outer_joins(child, c) } @@ -171,7 +171,7 @@ module ActiveRecord def make_inner_joins(parent, child) tables = child.tables - join_type = Arel::InnerJoin + join_type = Arel::Nodes::InnerJoin joins = make_constraints parent, child, tables, join_type joins.concat child.children.flat_map { |c| make_inner_joins(child, c) } -- cgit v1.2.3 From c24ea241e224b2d58e3184fa119beddac096b1f2 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 14 Feb 2014 16:47:03 -0800 Subject: make most parameters to the AliasTracker required This helps with our sanity. The class is internal, we can refactor to a "nice" API later. --- activerecord/lib/active_record/associations/join_dependency.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activerecord/lib/active_record/associations/join_dependency.rb') diff --git a/activerecord/lib/active_record/associations/join_dependency.rb b/activerecord/lib/active_record/associations/join_dependency.rb index 27069157be..1c8a44d0c5 100644 --- a/activerecord/lib/active_record/associations/join_dependency.rb +++ b/activerecord/lib/active_record/associations/join_dependency.rb @@ -94,7 +94,7 @@ module ActiveRecord # def initialize(base, associations, joins) @alias_tracker = AliasTracker.new(base.connection, joins) - @alias_tracker.aliased_name_for(base.table_name) # Updates the count for base.table_name to 1 + @alias_tracker.aliased_name_for(base.table_name, base.table_name) # Updates the count for base.table_name to 1 tree = self.class.make_tree associations @join_root = JoinBase.new base, build(tree, base) @join_root.children.each { |child| construct_tables! @join_root, child } -- cgit v1.2.3 From bfc776f7bb114e90cf91f16f5892be636ed2f0c8 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 14 Feb 2014 18:01:12 -0800 Subject: add factory methods for empty alias trackers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If we know the alias tracker is empty, we can create one that doesn't use a hash with default block for counting. ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:') ActiveRecord::Schema.define do create_table :posts, force: true do |t| t.integer :comments_count end create_table :comments, force: true do |t| t.integer :post_id end end class Post < ActiveRecord::Base; has_many :comments; end class Comment < ActiveRecord::Base; belongs_to :post, counter_cache: true; end 10.times { Comment.create!(post: Post.create!) } record = Post.first association_name = :comments Benchmark.ips do |x| reflection = record.class.reflect_on_association(association_name) association = reflection.association_class.new(record, reflection) x.report('assoc') do reflection.association_class.new(record, reflection) end x.report('reader') do association.reader;nil end x.report('combined') do reflection.association_class.new(record, reflection).reader;nil end end [aaron@higgins rails (tracker)]$ TEST=ips bundle exec ruby ../1bb5456b5e035343df9d/gistfile1.rb -- create_table(:posts, {:force=>true}) -> 0.0062s -- create_table(:comments, {:force=>true}) -> 0.0003s Calculating ------------------------------------- assoc 833 i/100ms reader 28703 i/100ms combined 839 i/100ms ------------------------------------------------- assoc 9010.3 (±3.8%) i/s - 44982 in 5.000022s reader 3214523.4 (±5.5%) i/s - 16016274 in 5.001136s combined 8841.0 (±5.8%) i/s - 44467 in 5.049269s [aaron@higgins rails (tracker)]$ TEST=ips bundle exec ruby ../1bb5456b5e035343df9d/gistfile1.rb -- create_table(:posts, {:force=>true}) -> 0.0060s -- create_table(:comments, {:force=>true}) -> 0.0003s Calculating ------------------------------------- assoc 888 i/100ms reader 29217 i/100ms combined 900 i/100ms ------------------------------------------------- assoc 9674.3 (±3.3%) i/s - 48840 in 5.054022s reader 2988474.8 (±6.9%) i/s - 14842236 in 4.998230s combined 9674.0 (±3.1%) i/s - 48600 in 5.028694s --- activerecord/lib/active_record/associations/join_dependency.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activerecord/lib/active_record/associations/join_dependency.rb') diff --git a/activerecord/lib/active_record/associations/join_dependency.rb b/activerecord/lib/active_record/associations/join_dependency.rb index 1c8a44d0c5..94f69d4c2d 100644 --- a/activerecord/lib/active_record/associations/join_dependency.rb +++ b/activerecord/lib/active_record/associations/join_dependency.rb @@ -93,7 +93,7 @@ module ActiveRecord # joins # => [] # def initialize(base, associations, joins) - @alias_tracker = AliasTracker.new(base.connection, joins) + @alias_tracker = AliasTracker.create(base.connection, joins) @alias_tracker.aliased_name_for(base.table_name, base.table_name) # Updates the count for base.table_name to 1 tree = self.class.make_tree associations @join_root = JoinBase.new base, build(tree, base) -- cgit v1.2.3