Skip to content
Browse files

cache join associations and join base on the stack

No reason to decompose the join objects on every iteration
  • Loading branch information...
1 parent eeda42f commit 96a366cd9b52a4e80b0cb36c20f4c0011159d745 @tenderlove tenderlove committed Oct 8, 2013
Showing with 11 additions and 4 deletions.
  1. +11 −4 activerecord/lib/active_record/associations/join_dependency.rb
View
15 activerecord/lib/active_record/associations/join_dependency.rb
@@ -62,10 +62,17 @@ def initialize(base, associations, joins)
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

0 comments on commit 96a366c

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