mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
performance improvements to joins!
Before:
Calculating -------------------------------------
ar 87 i/100ms
-------------------------------------------------
ar 823.4 (±11.8%) i/s - 4089 in 5.070234s
After:
Calculating -------------------------------------
ar 88 i/100ms
-------------------------------------------------
ar 894.1 (±3.9%) i/s - 4488 in 5.028161s
Same test as 3a6dfca7f5
This commit is contained in:
parent
3a6dfca7f5
commit
db8dbe76db
2 changed files with 13 additions and 5 deletions
|
@ -22,7 +22,17 @@ module ActiveRecord
|
|||
# the values.
|
||||
def other
|
||||
other = Relation.new(relation.klass, relation.table)
|
||||
hash.each { |k, v| other.send("#{k}!", v) }
|
||||
hash.each { |k, v|
|
||||
if k == :joins
|
||||
if Hash === v
|
||||
other.joins!(v)
|
||||
else
|
||||
other.joins!(*v)
|
||||
end
|
||||
else
|
||||
other.send("#{k}!", v)
|
||||
end
|
||||
}
|
||||
other
|
||||
end
|
||||
end
|
||||
|
@ -50,7 +60,7 @@ module ActiveRecord
|
|||
def merge
|
||||
normal_values.each do |name|
|
||||
value = values[name]
|
||||
relation.send("#{name}!", value) unless value.blank?
|
||||
relation.send("#{name}!", *value) unless value.blank?
|
||||
end
|
||||
|
||||
merge_multi_values
|
||||
|
|
|
@ -258,13 +258,11 @@ module ActiveRecord
|
|||
# User.joins(:posts)
|
||||
# => SELECT "users".* FROM "users" INNER JOIN "posts" ON "posts"."user_id" = "users"."id"
|
||||
def joins(*args)
|
||||
args.compact.blank? ? self : spawn.joins!(*args)
|
||||
args.compact.blank? ? self : spawn.joins!(*args.flatten)
|
||||
end
|
||||
|
||||
# Like #joins, but modifies relation in place.
|
||||
def joins!(*args)
|
||||
args.flatten!
|
||||
|
||||
self.joins_values += args
|
||||
self
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue