diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-10-08 15:46:06 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-10-08 15:46:06 -0700 |
commit | 96a366cd9b52a4e80b0cb36c20f4c0011159d745 (patch) | |
tree | 9a5db8f0ac6e69f2c5c21cd72618834e9fc31f72 /activerecord/lib | |
parent | eeda42fc11a4b2840bfa9bbdc7f3028638563ac7 (diff) | |
download | rails-96a366cd9b52a4e80b0cb36c20f4c0011159d745.tar.gz rails-96a366cd9b52a4e80b0cb36c20f4c0011159d745.tar.bz2 rails-96a366cd9b52a4e80b0cb36c20f4c0011159d745.zip |
cache join associations and join base on the stack
No reason to decompose the join objects on every iteration
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations/join_dependency.rb | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/associations/join_dependency.rb b/activerecord/lib/active_record/associations/join_dependency.rb index 8ddfe5742e..4d32fb8571 100644 --- a/activerecord/lib/active_record/associations/join_dependency.rb +++ b/activerecord/lib/active_record/associations/join_dependency.rb @@ -62,10 +62,17 @@ module ActiveRecord end def graft(*associations) - associations.each do |association| - join_associations.detect { |a| association == a } || - find_or_build_scalar(association.reflection.name, find_parent_part(association.parent) || join_base, association.join_type) - end + join_assocs = join_associations + base = join_base + + associations.reject { |association| + join_assocs.detect { |a| association == a } + }.each { |association| + name = association.reflection.name + join_part = find_parent_part(association.parent) || base + type = association.join_type + find_or_build_scalar name, join_part, type + } self end |